//Front end Java Script File
//$.noConflict();

jQuery(document).ready(function() 
{
// Enable Pretty Photo effect for Images 
//		jQuery("a[rel^='prettyPhoto']").prettyPhoto
//				({    
//					animationSpeed: 'normal', 		/* fast/slow/normal */
//					padding: 40, 					/* padding for each side of the picture */
//					opacity: 0.35, 					/* Value betwee 0 and 1 */
//					showTitle: false, 				/* true/false */
//					allowresize: false, 			/* true/false */
//					counter_separator_label: ' of ', /* The separator for the gallery counter 1 "of" 2 */
//					theme: 'light_rounded' 			/* light_rounded / dark_rounded / light_square / dark_square */
//				});



//			

	jQuery("form#email_form").submit(function() {
		jQuery('#success').css({"display":"none"});
		// we want to store the values from the form input box, then send via ajax below
		var frm1=validateformone();
		
		if(frm1)
		{
			
			var email_to     	  = $('#email_to').attr('value');
			var email_message     = $('#email_message').attr('value');
			var email_subject     = $('#email_subject').attr('value');
			email_val=email_to.split(",");
			 
			var myArray = new Array();


			for(var k=0;k<email_val.length;k++)
			{
				//alert(email_val[k]+ " " + trimAll(email_val[k]))
				emailformat=checkEmailFormat(trimAll(email_val[k]));
				if(emailformat==false)
				{
				$('#email_to').css({"background":"#FF99CC"});
				return false;
				}
				else
				{
					
					myArray[k]=email_val[k];
				}
			}
			
			//alert(myArray);
			
		 	 
				jQuery.ajax({
					type: "POST",
					url: "sendmail.php",
					data: "email_to="+ email_to +"& email_message="+ email_message + "& email_subject="+email_subject,
					success: function(msg){
					//alert(msg);	
					if(msg=="success")
					{
							document.email_form.reset()
							//$('#content').css({"display":"none"});
							$('#success').fadeIn("slow").css({"display":"inline"});
					}
					}
				});
			
		}
		return false;
	});
	
	jQuery('#mycarousel').jcarousel();
	
jQuery(".jcarousel-prev").bind('hover',function() { 
	jQuery(".carousel_txt_right").fadeOut(10,function (){ jQuery(".carousel_txt_right").show(700); });
	jQuery(".carousel_txt_left").fadeOut(10, function () { jQuery(".carousel_txt_left").show(700); } );
});

jQuery(".jcarousel-next").bind('click',function() {
	jQuery(".carousel_txt_right").fadeOut(10,function (){ jQuery(".carousel_txt_right").show(700); });
	jQuery(".carousel_txt_left").fadeOut(10, function () { jQuery(".carousel_txt_left").show(700); } );
	});	
	
	
	
jQuery("#albumlink_prev").click(showPrevImagesBottom);	 
jQuery("#albumlink_next").click(showNextImagesBottom);


jQuery(".menu ul li").hover(function(){
		
	if(jQuery(this).children().hasClass("sub_menu"))
	{
		jQuery(this).removeClass("selected").addClass("selected_submenu");	
	}
	jQuery(this).children(".sub_menu").css("display","block");
	//console.log("in");
},function(){

if(jQuery(this).children().hasClass("sub_menu"))
{
jQuery(this).removeClass("selected_submenu");
}
jQuery(this).children(".sub_menu").css("display","none");
//console.log("out");
});


   		
});

function showPrevImagesBottom()
{
	
	var totalval=jQuery("#totalalbumid").val();
	var curvalue=jQuery("#current_albumid").val();
	if(curvalue!=0)
	{	
		if(totalval<6)
		{
			return false;
		}
		else
		{
			curvalue=parseInt(curvalue)-6;
		}
		
		var k=1;
		if(totalval!=curvalue)
		{
			jQuery('#album_bottom_id div.album_content').css({"display":"none"});
			jQuery('#album_bottom_id div.album_content').each(function(i) {
				if(i>=curvalue)
				{
				  if(k<=6)	
				  {
					  jQuery("#albumid_"+i).css({"display":"block"});
					  jQuery("#current_albumid").val(curvalue);
					  k++;
					  jQuery("#last_index_page").val(k-1);
				  }
				}   
			});	
		}
	}
	
}

function showNextImagesBottom()
{
	
	var totalval=jQuery("#totalalbumid").val();
	var curvalue=jQuery("#current_albumid").val();
	if(totalval<6)
		return false;
	else
	{
		if(curvalue!=(parseInt(totalval)-parseInt(jQuery("#last_index_page").val())))
		{	
			if(totalval<6)
				curvalue=parseInt(curvalue);
		    else		
			    curvalue=parseInt(curvalue)+6;
			var k=1;
			if(totalval!=curvalue)
			{
				jQuery('#album_bottom_id div.album_content').css({"display":"none"});
				jQuery('#album_bottom_id div.album_content').each(function(i) {
					if(i>=curvalue)
					{
					  if(k<=6)	
					  {
						  jQuery("#albumid_"+i).css({"display":"block"});
						  jQuery("#current_albumid").val(curvalue);
						  k++;
						  jQuery("#last_index_page").val(k-1);
					  }
					}   
				});	
			}
		}
	}

	
}

jQuery(document).ready(function()
{  

	jQuery(".album_bg").hover(function() 
		{
		jQuery(this).next(".album_tooltip").stop(true, true).animate({opacity: "show", top: "-53"}, "slow");
		}, 
	function() 
		{
			jQuery(this).next(".album_tooltip").animate({opacity: "hide", top: "-58"}, "slow");
		});
	
	
	var len = jQuery("a.act img").length;
	
	for(i=0;i<len;i++)
	{
		var sr = jQuery("a.act img:first").attr("src");
		video_play(sr);
		break;
	}
	
	jQuery("a.act img").bind('click',function() {
		
		
		var v = jQuery(this).attr("src");
		video_play(v);
	});
	
	
	
	
	
 });

function video_play(v)
{
	v = v.split("/");
	var len = v.length-2;
	var val = v[len];
	var str = '<object width="880" height="495"><param name="movie" value="http://www.youtube.com/v/'+val+'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'+val+'" type="application/x-shockwave-flash" wmode="transparent" width="880" height="495"></embed></object>';
	jQuery("#video_player").html(str);

}


jQuery(document).ready(function(){
		
	jQuery(".act").bind('click', function (){
		var strid=jQuery(this).attr('id');
		showPicasaAlbum(strid);
		});
	
		
});
	
var piccasa_album_list = new Array();	
function showPicasaAlbum(strid1)
{
	var str=strid1.split("_");
    var strval='';
    var len="";
    jQuery.getJSON("_scripts/_JS/json_picasa.js",{ num: Math.random() },
		function(data){
    	
			if(data.albumid[str[2]].album_id==str[3])
			{
				//console.log(data.albumid[str[2]].content_url.length);
				
				len = data.albumid[str[2]].content_url.length;
				
				strval+='<div align="center" class="ad-gallery"><div class="ad-image-wrapper"></div><div class="ad-nav"><div class="ad-thumbs"><ul class="ad-thumb-list">';
				
				//strval+="<ul class='ad-thumb-list'>"
				for(i=0;i<len;i++)
				{
					strval+='<li>';
					strval+='<a href="'+data.albumid[str[2]].content_url[i]+'" title="gallery"><img src="'+data.albumid[str[2]].thumb_url[i]+'" class="ad_gal_desc"  border="0" title="" /></a>';
					strval+='</li>';
					
				}
				strval+="</ul></div></div></div>"
				jQuery("#picasa").html("");
				jQuery("#picasa").html(strval); //alert(len);
			}
			//alert(strval);
			var galleries = $('.ad-gallery').adGallery({
				 loader_image: siteURL + '_images/ad-gallery/loader.gif',
				  width: 880, // Width of the image, set to false and it will read the CSS width
				  height: 650, // Height of the image, set to false and it will read the CSS height
				  effect: 'fade' // or 'slide-vert', 'resize', 'fade', 'none' or false
       
			});
			jQuery("#gallery_list").slideUp("slow");
			jQuery("#albums span").toggleClass("active");
    });
 
	
}


jQuery(document).ready(function() 
		{
		 jQuery("#albums").click(function(){
				if (jQuery("#gallery_list").is(":hidden")){
					jQuery("#gallery_list").slideDown("slow");
					jQuery("#albums span").toggleClass("active");
				}
				else{
					jQuery("#gallery_list").slideUp("slow");
					jQuery("#albums span").toggleClass("active");
				}
			});
		});
		 
		 jQuery(document).ready(function() 
		{
		 jQuery("#videos").click(function(){
				if (jQuery("#video_list").is(":hidden")){
					jQuery("#video_list").slideDown("slow");
					jQuery("#videos span").toggleClass("active");
				}
				else{
					jQuery("#video_list").slideUp("slow");
					jQuery("#videos span").toggleClass("active");
				}
			});
		 jQuery(".next_arrow").bind("click",function() {
				var idv = jQuery(this).attr("id");
				idv = idv.split("_");
				idv = idv[1];
				var idval = parseInt(idv)+1;
				idv=idval;
				jQuery(".next_arrow").css({"display":"inline"}).attr("id","next_"+idval);
				jQuery(".prev_arrow").css({"display":"inline"}).attr("id","prev_"+idval);
				picassa_page(idv,"next");						  
		  });
		 jQuery(".prev_arrow").bind("click",function() {
				var idv = jQuery(this).attr("id");
				idv = idv.split("_");
				idv = idv[1];
				var idval = parseInt(idv)-1;
				idv=idval;
				jQuery(".next_arrow").css({"display":"inline"}).attr("id","next_"+idval);
				jQuery(".prev_arrow").css({"display":"inline"}).attr("id","prev_"+idval);
				picassa_page(idv,"prev");						  
		  });
		 picassa_page('0',"next");	
		});

	function picassa_page(idv,sta)
	{
		
		if(idv==0)
		   jQuery(".prev_arrow").css({"display":"none"});
		   
		var len = jQuery("#picasalist_id li").length;
		var st = parseInt(idv)*5;
		var en = parseInt(st)+5; 
		if(st==0)
		  jQuery(".prev_arrow").css({"display":"none"});
		if(en>=len)
		  jQuery(".next_arrow").css({"display":"none"});
		  
		jQuery("#picasalist_id li").css({"display":"none"})
		for(i=st;i<en;i++)
		{
			jQuery("#picasalist_id li:eq("+i+")").css({"display":"inline"});
		}	
	}

function validateformone()
{
	var flag=true;
	var email_to     = jQuery('#email_to').attr('value');
	var email_message     = jQuery('#email_message').attr('value');
	var email_subject    = jQuery('#email_subject').attr('value');
	if(email_to=="")
	{
		jQuery('#email_to').css({"background":"#FF99CC"});
		flag=false;
	}
	else
	{
		jQuery('#email_to').css({"background":"#FFFFFF"});
	}
	
	if(email_subject=="")
	{
		jQuery('#email_subject').css({"background":"#FF99CC"});
		flag=false;
	}
	else
	{
		jQuery('#email_subject').css({"background":"#FFFFFF"});
	}
	
	return flag;
}

function checkEmailFormat(elementValue)
{
	var flag1=true;
	var emailPattern=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
//	var elementValue=$("#"+textidval).val();
	//alert(elementValue);
	if(elementValue=='')
	{
		flag1=false;
	}
	if(!emailPattern.test(elementValue))
    {
		
		flag1=false;
    }
    else
    {}
	return flag1;
}
function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		//limitCount.value = limitNum - limitField.value.length;
	}
}

function trimAll(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
} 
