/*	***********************************************
 *	jQuery Navigation for Lightbox Gallery
 *	Also includes: jQuery & CSS Onion Layer Shadows
 *	Author: Baysaa Boroo
 *	Date: 2009
 *	Version: 1.01
 *	***********************************************/

var $j = jQuery.noConflict();
var $padStyle = $j("#padStyle").val();

$j(document).ready(function(){
	var $galleryPages = $j(".galleryPage");
	var $moveFirst = $j(".moveFirst");
	var $moveLast = $j(".moveLast");
	var $movePrevious = $j(".movePrevious");
	var $moveNext = $j(".moveNext");
	var $cur = 0;
	var $old = 0;
	var $total = $galleryPages.size() - 1;
	var $thisPage = $j(".currentPage");
	var $totalPage = $j(".totalPage");
	
	$galleryPages.not(":eq(0)").css("display","none");
	$moveFirst.click(function(e){ e.preventDefault(); moveFirst(); });
	$moveLast.click(function(e){ e.preventDefault(); moveLast(); });
	$moveNext.click(function(e){ e.preventDefault(); moveNext(); });
	$movePrevious.click(function(e){ e.preventDefault(); movePrevious(); });
	//$j(".dropshadow").wrap("<div class='wrap1'><div class='wrap2'><div class='wrap3'></div></div></div>");
	//$j(".wrap1").append("<div style='clear:both;'></div>");
	
// Navigation Functions --->
	function moveFirst(){
		$cur = 0;
		move();
		$old = 0;
		checkLinks();
	}
	
	function moveLast(){
		$cur = $total;
		move();
		$old = $cur;
		checkLinks();
	}
	
	function moveNext(){
		$cur = ($old + 1);
		if($cur <= $total){
			move();
		}else{
			$cur = $total;
		}
		$old = $cur;
		checkLinks();
	}
	
	function movePrevious(){
		$cur = ($old - 1);
		if($cur >= 0){
			move();
		}else{
			$cur = 0;
		}
		$old = $cur;
		checkLinks();
	}
	
	function move(){
		$galleryPages.eq($old).css("display","none");
		$galleryPages.eq($cur).css("display","block");
	}

	/*function checkLinks(){
		//alert($cur);
		if($cur <= 0){ $movePrevious.attr("disabled","disabled"); $moveFirst.attr("disabled","disabled"); }
		if($cur >= $total){ $moveNext.attr("disabled","disabled"); $moveLast.attr("disabled","disabled"); }
		if($cur > 0){ $movePrevious.removeAttr("disabled"); $moveFirst.removeAttr("disabled"); }
		if($cur < $total){ $moveNext.removeAttr("disabled"); $moveLast.removeAttr("disabled"); }
		updateText()
	}*/
	
	function checkLinks(){
		//alert($cur);
		if($cur <= 0){ $movePrevious.hide(0); $moveFirst.hide(0); }
		if($cur >= $total){ $moveNext.hide(0); $moveLast.hide(0); }
		if($cur > 0){ $movePrevious.show(0); $moveFirst.show(0); }
		if($cur < $total){ $moveNext.show(0); $moveLast.show(0); }
		updateText()
		return false;
	}

	function updateText(){
		$thisPage.text($cur+1);
	}
// Navigation Functions End -->

	checkLinks();
	$totalPage.html($total+1);
});