var video = null;

$(document).ready(function(){

		
		$("#video-link").click(function(){
			
			$("#video-wrkshp").show("slow", $.showVideo(video));

		});

		$("#video-link-close").click(function(){
			
			$("#video-wrkshp").hide("slow");
			//$("#video-wrkshp").flash(function(){this.GotoFrame(10)});
			$("#video-wrkshp .movie").html('');
			$('#slideshow').cycle('resume');

		});

		/*
		$.fn.cycle.defaults = { 
		    timeout:       3000,  // milliseconds between slide transitions (0 to disable auto advance) 
		    speed:         1000,  // speed of the transition (any valid fx speed value) 
		    next:          null,  // id of element to use as click trigger for next slide 
		    prev:          null,  // id of element to use as click trigger for previous slide 
		    before:        null,  // transition callback (scope set to element to be shown) 
		    after:         onAfter,  // transition callback (scope set to element that was shown) 
		    height:       'auto', // container height 
		    sync:          0,     // true if in/out transitions should occur simultaneously 
		    fit:           0,     // force slides to fit container 
		    pause:         0,     // true to enable "pause on hover" 
		    delay:         0,     // additional delay (in ms) for first transition (hint: can be negative) 
		    slideExpr:     null   // expression for selecting slides (if something other than all children is required) 
		}; 
		
		*/

		$('#slideshow').cycle({
			fx: 		'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		    sync:		0,     // true if in/out transitions should occur simultaneously 
		    after:         onAfter,  // transition callback (scope set to element that was shown) 
		   next:   '#nextphoto', 
		   prev:   '#prevphoto'
		});
		
});

jQuery.showVideo = function(v){
	
	$('#video-wrkshp .movie').flash(
		{
			swf: 'vplayer.swf',
			params: {
				play: false
			},
			flashvars: {
				v: v,
				message: 'I come from Flash.'
			},
			width: 505,
			height: 296
		}
	);
};

var currSlide = -1;
var lastSlide = -1;

function onAfter(curr,next,opts) {
	
	currSlide = opts.currSlide;
	
	/*
	lastSlide = currSlide - 1;
	if (lastSlide == 0)
		lastSlide = opts.slideCount;
	*/
	
	if (lastSlide >= 0)
		$("#p"+	lastSlide).removeClass("on");
		
	$("#p"+	currSlide).addClass("on");
	lastSlide = currSlide;

	
	//var caption = 'Image ' + (opts.currSlide + 1) + ' of ' + opts.slideCount;
	//$('#caption').html(caption);
}



userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function findElement(n,ly) {
	if (browserVers < 4)		return document[n];
	var curDoc = ly ? ly.document : document;
	var elem = curDoc[n];
	if (!elem) {
		for (var i=0;i<curDoc.layers.length;i++) {
			elem = findElement(n,curDoc.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		var img;
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			img = null;
			if (document.layers) {
				img = findElement(changeImages.arguments[i],0);
			}
			else {
				img = document.images[changeImages.arguments[i]];
			}
			if (img) {
				img.src = changeImages.arguments[i+1];
			}
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		b1_over = newImage("images/arrow_more_on.png");
		bcv_over = newImage("images/bcv-over.gif");
		preloadFlag = true;
	}
}

function getboxbyname(name){
	
	var box;
	
	if (document.getElementById)
		box = document.getElementById(name);
	else if (document.all)
		box = document.all[name];
		
	return box;
}


function mover(box){
	
	box.className='menu_sel';

}

function mout(box, clss){
	
	box.className='menu_'+clss+'_item';

}

function swclass(box, clss) {
	
	box.className=clss;

}

/*
function moverindx(box){
	
	if (box.id != 'p'+photoindx){
		swclass(box,'photo-index-box-on');
	}
}

function moutindx(box){
	
	if (box.id != 'p'+photoindx){
		swclass(box,'photo-index-box');
	}
}

function prvphoto(){
	
	photoindx--;
	if (photoindx < 1){
		photoindx = photos.length;
	}
	swphoto(photoindx-1);			
}

function nxtphoto(){
	
	var oldbox = getboxbyname('p'+photoindx);
	
	if (oldbox)
		swclass(oldbox,'photo-index-box');

	photoindx++;
	if (photoindx > photos.length){
		photoindx = 1;
	}
	swphoto(photoindx-1);			
}
*/

function wrkshpvideo(status){
	
	var videobox = getboxbyname('video-wrkshp');
	
	if (videobox){
		if (status == 1){
			$('#slideshow').cycle('pause');
			videobox.style.display="block";
		}else{
			
			// handled by jquery

		}
	}
	
}

/*
var sstimer = null;

function tmnxtphoto(){
	
	nxtphoto();
	sstimer = setTimeout("tmnxtphoto()",2000);
	
}

function timerphoto(force){
	
	return;
	
	if (force == true || sstimer != null){
		clearTimeout(sstimer);
		sstimer = null;
	}else{
		tmnxtphoto();
	}
	
}
*/

function swphoto(i){
	
	//alert(i);
	//$('#slideshow').cycle('stop');
	currSlide = i;
	
	if (lastSlide >= 0)
		$("#p"+	lastSlide).removeClass("on");
		
	$("#p"+	currSlide).addClass("on");
	lastSlide = currSlide;

	$('#slideshow').cycle(currSlide);
	$('#slideshow').cycle('pause');
	
	/*
	img = document.images.lphoto;
	setOpacity(img,0);
	img.src=photos[i];
	fadeIn('lphoto',0);


	//var imgBox = getboxbyname('lphoto');
	//imgBox.style.backgroundImage='url('+photos[i]+')';

	var oldbox = getboxbyname('p'+photoindx);
	swclass(oldbox,'photo-index-box');
	photoindx = i+1;
	var newbox = getboxbyname('p'+photoindx);
	swclass(newbox,'photo-index-box-on');
	*/
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 20;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}

function fadeOut(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity >= 0) {
      setOpacity(obj, opacity);
      opacity -= 20;
      window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 100);
    }else{
    	obj.style.display='none';
    }
  }
}

var lbtop = 0;
var pbtop = 0;
var pbpos = 0;
var scrcnt = 16;
var scrdir = 0;
var scrtmt = 0;
var scrpage = 0;
var maxpages = 0;
var maxlines = 10;

function scrollup(){
	
	if (scrpage > 0){
		scrcnt = 16*maxlines;
		scrdir = 0;
		scrtmt = 0;
		scrpage--;
		setTimeout(scrollbox,0);
	}
}

function scrolldown(){
	
	if (scrpage < maxpages){
		scrcnt = 16*maxlines;
		scrdir = 1;
		scrtmt = 0;
		scrpage++;
		setTimeout(scrollbox,0);
	}
}

function scrollbox(){

	var step = 2;
	var lbox = getboxbyname('list_box');
	var pbox = getboxbyname('ptr_box');
	
	if (scrcnt > 0){
		
		if (scrdir == 1){
			lbtop -= step;
			pbpos -= step;
		}else{
			lbtop += step;
			pbpos += step;
		}
		
		lbox.style.top = lbtop+"px";
		
		if (pbox)
			pbox.style.top = pbtop+8+pbpos+"px";
			
		scrcnt -= step;

		//if (scrtmt < 10)
		//	scrtmt += 3;
		
		setTimeout(scrollbox,10);

	}
}

jQuery.showPopup = function(){
	
	$("#popup").fadeIn("slow");
	
}

jQuery.hidePopup = function(){
	
	$("#popup").fadeOut("fast");
	
}


