var visible = true;
var visibleVer = true;
var slideshow = true;
var slideshowOK = true;

$(document).ready(function() {
	//hide all the images on the page
	$('img').hide();

	document.images["big"].width = screen.width;
		
	$(".slideshowButton").click(function(){ 
		if(slideshow){
			// slideshow on					
			$('.slideshowImg').attr('src',"assets/templates/atelje-princ/img/stop.jpg");
			slideshow = false;
			if(visible){hideBar();}
			if(visibleVer){hideBarVer();}
			$('.slideshowButton').animate({ 'right': '0px' }, 'fast');
			playSlideshow();
		}else{
			// slideshow off
		  	$('.slideshowImg').attr('src',"assets/templates/atelje-princ/img/play.jpg");	  	
		  	slideshow = true;
		  	if(visible==false){showBar();}
		  	if(visibleVer==false){showBarVer();}
		  	$('.slideshowButton').animate({ 'right': '110px' }, 'fast');
			stopSlideshow();
		}
	});
	
	$(".toggleButtonHor").click(function(){ 
		//alert("visible: "+visible);
		if(visible){
			hideBar();		
		}else{
			showBar();
		}
	});
	$(".toggleButtonVer").click(function(){
		if(visibleVer){
			hideBarVer();		
		}else{
			showBarVer();
		}	
	});
	function hideBar() {
		//alert("hideBar");
		$('.toggleButtonHor').animate({ 'bottom': '0px' }, 'fast');
		$('.slideshowButton').animate({ 'bottom': '0px' }, 'fast');
		$('.imageSlider').toggle('fast');
		$('.buttImgHor').attr('src',"assets/templates/atelje-princ/img/show-hor.jpg");
		visible = false;
	}
	function showBar() {
		$('.toggleButtonHor').animate({ 'bottom': '140px' }, 'fast');
		$('.slideshowButton').animate({ 'bottom': '140px' }, 'fast');
		$('.imageSlider').toggle('fast');
		$('.buttImgHor').attr('src',"assets/templates/atelje-princ/img/hide-hor.jpg");
		visible = true;
	}
	function hideBarVer() {
		$('.toggleButtonVer').animate({ 'right': '0px' }, 'fast');
		$('.rightBox').toggle('fast');
		$('.buttImgVer').attr('src',"assets/templates/atelje-princ/img/show-ver.jpg");
		visibleVer = false;
	}
	function showBarVer() {
		$('.toggleButtonVer').animate({ 'right': '517px' }, 'fast');
		$('.rightBox').toggle('fast');
		$('.buttImgVer').attr('src',"assets/templates/atelje-princ/img/hide-ver.jpg");
		visibleVer = true;
	}
	$("div#makeMeScrollable").smoothDivScroll({
		scrollingSpeed: 15, 
		mouseDownSpeedBooster: 3, 
		autoScroll: "", 
		autoScrollDirection: "endlessloop", 
		autoScrollSpeed: 1, 
		visibleHotSpots: "onstart", 
		hotSpotsVisibleTime: 0, 
		startAtElementId: "startAtMe"
	});
});

var i = 0;//initialize
var bint=0;//Internet Explorer Fix

$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
	bint = setInterval("doThis(i)",444);//444 is the fade in speed in milliseconds
});

function doThis() {
	var imagess = $('img').length;//count the number of images on the page

	if (i >= imagess) {// Loop the images
		clearInterval(bint);//When it reaches the last image the loop ends
	}

	$('img:hidden').eq(0).fadeIn(444);//fades in the hidden images one by one
		i++;//add 1 to the count
}

function changeBg(imgURL){
	
	$("#supersize img").fadeOut("normal");
	setTimeout('document.images["big"].src = "'+imgURL+'";', 500);
	document.images["big"].width = screen.width;

	setTimeout('$("#supersize img").fadeIn("slow")', 999);
}

var b = 0;
var cint=0;

function playSlideshow() {
	cint = setInterval("playSlide()",5000);
	slideshowOK = true;
	changeToFirstImage(document.images["big"].src);
}

function stopSlideshow() {
	clearInterval(cint);
	b = 0;
	slideshowOK = false;
	slideshow = true;
	visible = true;
	visibleVer = true;
}