/* 
	Gallery side menu.  Written by Hanan Mahmood August 11, 2008.  
	Uses CSS styles defined in 
*/
$(document).ready(function(){
 	links = $(".menu").children(".link");
	$(links).click(function(e){
		$(this).siblings().slideToggle(800);

		/*change the background image of collpassible menu arrow.  
		By default the ".link" class has background image with 
		closed arrow ">"				
		*/
		$(this).toggleClass("collapsedMenu");
		e.preventDefault(); 
		
	});
	
 
	//show category driven specific menu
	categoryParam = $.getURLParam("model");
	if (!(categoryParam== null))
	{
		allAnchors = $("#galleryMenu").find("a");
		$(allAnchors).hide();
		$.each(allAnchors, function(){
			if ($(this).attr("category")==categoryParam)
			{
				$(this).show();
				$(this).parent().show();
				$(this).parent().parent().children(links).show();
				$(this).parent().siblings(".link").addClass("collapsedMenu");
				$(this).attr("href", function(){
					return $(this).attr("href") + "?model=" + categoryParam
				});			
			}
		});
	}		
 
	// collapse appropriate menu
	var page = parseFileName(location.href);
	subMenuAnchors = $(".subMenu").children("a");
	menuAnchors = $(".menu").children("a");
	$.each(subMenuAnchors, function(){
	    if ($(this).attr("href").indexOf(page) > -1)
    	{
			$(this).parent().css({"background":"#3D5DAE none repeat scroll 0%", "color" : "#fff"});
		   	$(this).css("color", "#fff");
			$(this).parent().parent().children().show();
			$(this).parent().siblings(".link").addClass("collapsedMenu");
		}
	});
	$.each(menuAnchors, function(){
	    if ($(this).attr("href").indexOf(page) > -1)
    	{
			$(this).parent().css({"background":"#0B3956 none repeat scroll 0%", "color" : "#fff"});
			$(this).css("color", "#fff");
		}
	});	
	
	$("#galleryMenu").show();
});


/* Photo Gallery.  Written by Hanan Mahmood. */
$(document).ready(function () {
	photosArray = $(".lightbox-tour");
	photosCount = photosArray.size();	
	currentIndex = 0;
	
	//static variables
	firstPhotoIndex = 0;
	lastPhotoIndex  = photosCount-1;
	updateCaption();
//	previousPhotoIndex =  ((currentIndex > 0) && (currentIndex < photosCount)) ? (param-1) : 0;

	

	$("#largeImage").attr("src",photosArray[firstPhotoIndex].href); 
	
	$("#prev").click(function(){
		if(currentIndex==firstPhotoIndex)
		{
			currentIndex = lastPhotoIndex;
			$("#largeImage").attr("src",photosArray[currentIndex].href);
		}
		
		else// if(currentIndex <= (lastPhotoIndex))
		{
			currentIndex-=1;
			$("#largeImage").attr("src",photosArray[currentIndex].href);
			
		}
			updateCaption();
			refreshAds('Janice Dickinson Photo Galleries');
			return false;		
	});
	
	$("#next").click(function(){
		if(currentIndex < lastPhotoIndex)
		{
			currentIndex = currentIndex+1;
			$("#largeImage").attr("src",photosArray[currentIndex].href);
		}
		
		else //if(currentIndex == (lastPhotoIndex))
		{
			currentIndex=firstPhotoIndex;
			$("#largeImage").attr("src",photosArray[currentIndex].href);
		}
			updateCaption();
			refreshAds('Janice Dickinson Photo Galleries');	
			return false;	
	});
		function updateCaption()
		{	
			caption = $(photosArray[currentIndex]).attr("title");
			$("#photoCaption").html(caption);
			$("#photoIndex").html((currentIndex+1) + " of " + photosCount);
//			$(caption).appendTo(
//			alert(caption);
		}	
});

