// JavaScript Document

var myx = 0;
var i;

function doswitch(myvar){
	myx = myvar;
	
	switchimgto();
	
	$(document).stopTime("graphictimer");
	graphictimer();
}



function graphictimer() {
	
	var maxcount = 6;
	var currentcount = 0;
	
	$('#graphictimer').css('opacity', 0.3);
	
	myimgs = $('#mainprojector > a');
	myimglength = myimgs.length;
	
	
	$(document).everyTime(1500, 'graphictimer', function() {
		
		if(currentcount<maxcount){
			
			$('#graphictimer').css('background-image', 'url(images/timer2/timer'+currentcount+'.png)');
			currentcount++;
			
		}else{
			
			if(myx<myimglength){
				myx++;
		  }else{
				myx=0;
		  }
		  if(myx != myimglength){
		  	switchimgto();
		  }
			
			currentcount = 0;
		}
	});
}



function switchimgto() {
	
	if ( $.browser.msie ) {
		myimgs = $('#mainprojector').children('div').children('a');
	}else{
		myimgs = $('#mainprojector > a');
	}
	
	var myindex = 0;
	var myindexllength = myimgs.length;
	
	for(y=0;y<myindexllength;y++){
		
		// find what img is visible; Y is index of current img
		if(myimgs.eq(y).css('display') == 'block'){
			//determine if img you want to see has higher index than img that is currently visible
			$('.descriptioninnerwrapper2').eq(y).hide(500, function(){
				$('.descriptioninnerwrapper2').eq(myx).show(500);
			});
				
			if(myx > y){
				//because x is higher index than y show new img first and then hide rest of images
				myimgs.eq(myx).show(1000, function(){
						while(myx != myindex) {
							myimgs.eq(myindex).hide()
							myindex++;
						}
				});
				$('#controll li').eq(myx).addClass("current_myimg");
				$('#controll li').eq(y).removeClass("current_myimg");
			}
			
			if(myx < y){
				myimgs.eq(myx).show();
				
				while(myx != myindexllength) {
					myimgs.eq(myindexllength).hide(1000);
					myindexllength--;
				}
				$('#controll li').eq(myx).addClass("current_myimg");
				$('#controll li').eq(y).removeClass("current_myimg");
			}
			
			
		} //first if end
		
	} // first for end
	
} // function end

function imgsstartup() {
	myimgs = $('#mainprojector > a');
	
	for(x=0;x<myimgs.length;x++){
		$('#mainprojector > a').eq(x).hide();
		$('.descriptioninnerwrapper2').eq(x).hide();
	}
	
	$('#mainprojector > a').eq(0).show();
	$('.descriptioninnerwrapper2').eq(0).show();
	$('#controll li').eq(0).addClass("current_myimg");	
}


jQuery(document).ready(function(){
	
	$("a[rel^='prettyPhoto']").prettyPhoto({
		changepicturecallback: function(){ $(document).stopTime("graphictimer"); }, /* Called everytime an item is shown/changed */
		callback: function(){ graphictimer(); } /* Called when prettyPhoto is closed */
			
	});
	
	// setup projector images #1 visible rest of theme invisible
	imgsstartup();
	
	$('#helpmorepic').css('opacity', 0);
	$('#description').css('opacity', 0.3);
	
	
	$('#morepic').bind("mouseenter", function(event){
		$('#helpmorepic').oneTime(1000, function() {
			$(this).animate({'opacity': 1}, 500);
		 });
	});
	
	$('#morepic').bind("mouseleave", function(event){
		$('#helpmorepic').stopTime().animate({'opacity': 0}, 500);
	});
	
	$('#mainprojector').bind("mouseenter", function(event){
		$('#description').stopTime().animate({'opacity': 1}, 500);
	});
	
	$('#mainprojector').bind("mouseleave", function(event){
		$('#description').oneTime(1500, function() {
			$(this).animate({'opacity': 0.3}, 500);
		 });
	});	
		
	graphictimer();
	
	if ( $.browser.msie ) {
		DD_roundies.addRule('#mainprojector', '10px');
		DD_roundies.addRule('#mainprojector a', '7px');
	}

});






