// JavaScript Document

var pct=0;
var handle=0;
var trueHover = false;

function update(){
	$("#proBar").reportprogress(++pct);
	if(pct==100){
	clearInterval(handle);
	pct=0;
	if ($('a.nivo-imageLink', '#sliderContainer').index() == 3) {
	$('a.nivo-imageLink', '#sliderContainer').eq(0).click();
	} else {
	$('a.nivo-imageLink', '#sliderContainer').next().click();
	}
	}
}


function resetProgress(){
        clearInterval(handle);
  		pct=0;
        $("#proBar").reportprogress(0);
        //alert(trueHover);
        if (trueHover == false) {
        	handle = setInterval("update()",42);
        }
        if (trueHover == true) {
        	clearInterval(handle);
        }
}

this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 150;
		yOffset = -320;
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY + xOffset) + "px")
			.css("left",(e.pageX - yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

$('document').ready(function(){
	
	Cufon.replace('.cufon', { fontFamily: 'MyrLight' });;  // Inicjalizacja Cufona
	Cufon.replace('.cufonWhite', { fontFamily: 'MyrCond' });;  // Inicjalizacja Cufona

	screenshotPreview();	
	
	$("li.m05 a, li.m05_en a, li.m05_fr a").click(function(){
		$("#toggledTop").slideToggle("slow");
		$(this).toggleClass("active"); 
		$("#mainMenu li a").toggleClass("", ':contains(".active")');
		return false;
	});


	
	$('#modelShowcase, #modelCatalog , #worksCatalog').cycle({      // Inicjalizacja CycleAll
   	 fx:     'scrollHorz', 
   	 speed:  'fast', 
   	 timeout: 0, 
   	 next:   '.next', 
   	 prev:   '.prev' 
	});	

	$('#modelPhotos ul').cycle({      // Inicjalizacja CycleAll
   	 fx:     'fade', 
   	 speed:  600, 
   	 timeout: 4000,
	 pasue: 1, 
   	 next:   '.next', 
   	 prev:   '.prev' 
	});	
	
	
	// ModelReel, hover effect	
	$("#modelShowcase .modelHolder div").hover(
	function() {
	    $(this).stop(true, true);
        $(this).animate({opacity: 1}, 300);
    }, 
	function (){
        $(this).animate( {opacity: 0}, 400);
	});

// ModelCatalog, hover effect	
	$("#modelCatalog ul li img , #worksCatalog .worksRow .work img").hover(
	function() {
	    $(this).stop(true, true);
        $(this).animate({opacity: 0.5}, 300);
    }, 
	function (){
        $(this).animate( {opacity: 1}, 400);
	});
	
	// Slider, hover effect	
	$("#sliderContainer").hover(
	  function () {
		clearInterval(handle);
		trueHover = true;
	  }, 
	  function () {
	  	handle = setInterval("update()",42);
	  	trueHover = false;
	  });
	  
	  // Element niegotowy
	  $('.notReady').click(function(){
		 alert('Przepraszamy, ale ten język jest w fazie wdrażania.'); 
	  });
		
// Lightbox
	$('#modelPhotos ul li a').lightBox();	
});


	$(window).load(function() {       // Inicjalizacja NivoSlider
 	   $('#sliderContainer').nivoSlider({
  		effect:'fade', 
        slices:15,
        animSpeed:500, 
        pauseTime:4000,
        startSlide:0, 
        directionNav:true,
        directionNavHide:false, 
        controlNav:false, 
        controlNavThumbs:false,
        controlNavThumbsFromRel:false, 
        controlNavThumbsSearch: '.jpg', 
        controlNavThumbsReplace: '_thumb.jpg', 
        keyboardNav:true, 
        pauseOnHover:true, 
        manualAdvance:false, 
        captionOpacity:1,
        beforeChange: function(){resetProgress();},
        afterChange: function(){},
        slideshowEnd: function(){}, 
        lastSlide: function(){}, 
        afterLoad: function(){} 
	   });
	});
