// JavaScript Document
jQuery(document).ready(function(){
	$j = jQuery;
	// home page animation
/*	$j("#home-image-navigation li").each(function(index, item){
		$j(new Image()).load().attr('src', $j(item).attr("title") );
		$j(this).bind('click', function(e){
			$j("#home-image-navigation li").removeClass("dot-current").addClass("dot");
			$j(this).removeClass("dot").addClass("dot-current");
			var newImageUrl  = $j(this).attr("title");
			$j("#home-image").fadeOut(1000, function(){
				$j("#home-image-tag").attr("src", newImageUrl ).load(function(){
					$j(this).parent().fadeIn(1000);														  
				});
			})
			e.preventDefault();
		});
	});
	
	// other page animation
	$j("#other-page-navigation li").each(function(index, item){
		$j(this).bind('click', function(e){
			$j("#other-page-navigation li").removeClass("dot-current").addClass("dot");
			$j(this).removeClass("dot").addClass("dot-current");
			
			$j("#pagecontentholder-current").fadeOut(600, function(){
				var pagecontentholderArray = $j(".pagecontentholder");
				// $j(this).removeClass("current");
				var newTitle = $j(pagecontentholderArray[index]).find("div.title").html();
				var newDescription = $j(pagecontentholderArray[index]).find("div.pagedescription").html();
				// alert( newTitle );
				$j(this).find("div.title").html( newTitle );
				$j(this).find("div.pagedescription").html( newDescription );
				$j(this).fadeIn(600);
				
			})
			e.preventDefault();
		});
	});
	// press page animation
	$j("#press-page-navigation li").each(function(index, item){
		$j(this).bind('click', function(e){
			$j("#press-page-navigation li").removeClass("dot-current").addClass("dot");
			$j(this).removeClass("dot").addClass("dot-current");
			
			$j("#pagecontentholder-current").fadeOut(600, function(){
				var pagecontentholderArray = $j(".pagecontentholder");
				// $j(this).removeClass("current");
				var newImageTitle = $j(pagecontentholderArray[index]).find(".imagearea div.title").html();
				var newImageTitleBlack = $j(pagecontentholderArray[index]).find(".imagearea div.titleblack").html();
				var newImage			= $j(pagecontentholderArray[index]).find(".imagearea img.press-image").attr('src');
				var newTitle 	= $j(pagecontentholderArray[index]).find(".descriptionarea div.title").html();
				var newDescription = $j(pagecontentholderArray[index]).find(".descriptionarea div.pagedescription").html();
				var newImageBig  = $j(pagecontentholderArray[index]).find(".imagearea img.press-image").attr('rel');
				// alert( newTitle );
				// image area
				$j(this).find("#imagearea div.title").html( newImageTitle );
				$j(this).find("#imagearea div.titleblack").html( newImageTitleBlack );
				// alert( newImage );
				$j(this).find("#imagearea #press-image-thumb").attr( 'src', newImage );
				$j(this).find("#imagearea #press-image-thumb").attr( 'rel', newImageBig );
				
				// description area 
				$j(this).find("#descriptionarea div.title").html( newTitle );
				$j(this).find("#descriptionarea div.pagedescription").html( newDescription );
				$j(this).fadeIn(600);
				
			})
			e.preventDefault();
		});
	});
	// light box events
	$j("#press-image-thumb").live('click', function(){
		$j("#lightbox").fadeIn(200);
		//alert( $j(this).attr('rel') );
		$j("#press-image").attr('src', $j(this).attr('rel') ).load(function(){
			$j("#press-image-container").show();
		});
		
	});	
	// light  box close
	$j("#lightbox .close, #lightbox").live('click', function(){
		$j("#lightbox").fadeOut(200);
		$j("#press-image-container").hide();
	});
	
	// collection page navigation start
	// other page animation
	$j("#collection-page-navigation li").each(function(index, item){
		$j(this).bind('click', function(e){
			$j("#collection-page-navigation li").removeClass("dot-current").addClass("dot");
			$j(this).removeClass("dot").addClass("dot-current");
			
			$j("#pagecontentholder-current").fadeOut(600, function(){
				var pagecontentholderArray = $j(".pagecontentholder");
				// $j(this).removeClass("current");
				var newTitle = $j(pagecontentholderArray[index]).find("div.title").html();
				var newDescription = $j(pagecontentholderArray[index]).find("div.pagedescription").html();
				var newImage		= $j(pagecontentholderArray[index]).find("img.collection-image-tag").attr('src');
				// alert( newTitle );
				$j(this).find("div.title").html( newTitle );
				$j(this).find("div.pagedescription").html( newDescription );
				$j("#collection-image-tag").attr( 'src', newImage );
				$j(this).fadeIn(600);
				
			})
			e.preventDefault();
		});
	});	
	// collection page navigation end 
	// contact us send button
	// bind action for send butto
	var error = false;
	$j("#send").live('click', function(e){
		// required validation
		$j(".required").each(function(){
			if( $j(this).val() == "" ){
				$j(this).addClass("error");
				error = true;
			} else {
				$j(this).removeClass("error");
				error = false;
			}
		});
		// email validation
		//var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+$/;
		$j(".email").each(function(){
			if( false == emailRegex.test($j(this).val())  ){
				$j(this).addClass("error");
				error = true;
			} else {
				$j(this).removeClass("error");
				error = false;
			}
		});
		// check the error is true or not
		// alert( error );
		if(false == error ){ // no error send the contact mail 
			var formData  = $j("#contactusform").serialize();
			$j("#contactusform").submit();
			
		} else {
			$j("#messageforindication").addClass("errortext").html("Please correct the error in the marked field ");
			$j("html body").animate({scrollTop:$j("#messageforindication").offset().top}, 1000);
		}
	});
	
// sub menu drop down
	$j("#homeMenu > li").live('click', function(){
		var $active = $j(this);	
		if( null !=  $j($active).find("ul").html() ){		
			$j($active).find("a:first").unbind().attr("href", "#");			
		}		
		$j("#homeMenu > li").addClass("link");
		$j($active).addClass("currentlink").removeClass("link");
		$j("#homeMenu li.link ul").fadeOut();
		makeSubmenuCenter($j($active).find("ul"));
		$j($active).find("ul").fadeIn();
	});
	// call this on page load to fix the design issue 
	makeSubmenuCenter($j("#homeMenu li.currentlink").find("ul"));
	
	*/// logo click event 
	$j("#logo").live('click', function(){
		window.location.href = 'index.php';								  
	});
	// contact us page events 
	$j("#contactusform").find("input, textarea").live("focus", function(){
		if( $j(this).val() == $j(this).attr('title') ){
			$j(this).val("");
		}
	});
	$j("#contactusform").find("input, textarea").live("blur", function(){
		if( $j(this).val() == "" ){
			$j(this).val( $j(this).attr('title') );
		}
	});
	if( 0 !=  $j("#contactusform").size() ) 
		$j("#contactusform").validate();
	// submit link event
	$j("#submitLink").live('click', function(e){
		$j("#contactusform").submit();
		e.preventDefault();
	});
});
makeSubmenuCenter = function($activeSubMenu){
		// small menu adjustments
	var newLeft =( parseInt( $j(document).width()) - parseInt( $j($activeSubMenu).width())) /2;
	$j($activeSubMenu).css('left', newLeft );
}

