$(document).ready(function(){
	$(".westTip").tipsy({gravity: 'w'});
	$(".southTip").tipsy({gravity: 's'});
	$(".northTip").tipsy({gravity: 'n'});	
	
	$('.contactForm .required').tipsy({trigger: 'blur', gravity: 'w'});

	
	var imageWidth = $(".window").width();
	var imageSum = $(".imageReel img").size();
	var imageReelWidth = imageWidth * imageSum;
	var triggerID = 0;
	var navNum = 1;
	
	$(".imageReel").css({'width' : imageReelWidth});
	
	$(".thisImage").html(navNum);
	$(".imageSum").html(imageSum);
	
	//slideRight
	rotate = function(){
    image_reelPosition = triggerID * imageWidth;
	
	//navi numbers
	$(".thisImage").html(navNum);

    //Slider Animation
	$(".imageReel").animate({
		left: -image_reelPosition
	}, 500);
	
	}; 

	

	$(".navBack a").click(function() {
		if (navNum > 1) {
			navNum--;
		}
		else{
			navNum = imageSum;
		}
		
		if (triggerID > 0){
			triggerID--;
		}
		else{
			triggerID = imageSum - 1;
		}
		
		rotate();
		
    return false;
	});

	
	$(".navNext a").click(function() {
		if (navNum < imageSum) {
			navNum++;
		}
		else{
			navNum = 1;
		}
		
		if (triggerID < imageSum - 1){
			triggerID++;
		}
		else{
			triggerID = 0;
		}
		
		rotate();
    return false;
	});
	
	$(".window .clicker").click(function() {
		if (navNum < imageSum) {
			navNum++;
		}
		else{
			navNum = 1;
		}
		
		if (triggerID < imageSum - 1){
			triggerID++;
		}
		else{
			triggerID = 0;
		}
		
		rotate();
	
    return false;
	});
	
//dodaj scroll
	$('.scroll-pane').jScrollPane({
		scrollbarWidth: 2,
		wheelSpeed: 60,
		dragMaxHeight: 200,
		enableKeyboardNavigation: false
	});

//przeładuj scrolla	
	reinitialiseScrollPane = function()
	{
		$('.scroll-pane').jScrollPane({
			scrollbarWidth: 2,
			wheelSpeed: 60,
			dragMaxHeight: 200
		});
	}
	
	$(".window").hover(
		function(){
			$(".window .dots").stop().animate({
				opacity: 0
			},200)
		},
		function(){
			$(".window .dots").stop().animate({
				opacity: 1
			},200)
		});
	
	$(".miniWorks .work:odd").css('margin-right','0px');
	$(".work a img").css('opacity','0.3');
	$(".work a .activeImg").css('opacity','1');
	

	$(".work").hover(
		function(){
			$(this).find("img").stop().animate({
				opacity: 1
			},200)
		},
		function(){
			$(this).find("img").not('.activeImg').stop().animate({
				opacity: 0.3
			},200)
		}
	);
	
	$(".work").hover(
		function(){
			$(this).find(".workTitle").stop().animate({
				bottom: '0px'
			},200)
		},
		function(){
			$(this).find(".workTitle").stop().animate({
				bottom: '-23px'
			},200)
		}
	);
	
	//shadowbox initialization	
	Shadowbox.init();
	
	//view switcher
	    $("a.switch_thumb").toggle(function(){
        $(this).addClass("swap");
        $("ul.display").fadeOut("fast", function() {
            $(this).fadeIn("fast").addClass("desc_view");
			reinitialiseScrollPane();
        });
    	}, function () {
        $(this).removeClass("swap");
        $("ul.display").fadeOut("fast", function() {
            $(this).fadeIn("fast").removeClass("desc_view");
			reinitialiseScrollPane();
        });
    	});
		
	
});

