// JavaScript Document


jQuery(function(){
	jQuery(".ulMenu > li").not("[@class='active']")
	.mouseover(function(){
		jQuery(this).stop().animate({backgroundPosition:"0px 0px",opacity:"10%"}, {duration:300})
		//jQuery(this).addClass("active");
		
	})
	.mouseout(function(){
		jQuery(this).stop().animate({backgroundPosition:"0px 33px",opacity:"100%"}, {duration:100})
		//jQuery(this).removeClass("active");
	})
	
	
	// news ticker
	var delayTime=5000;
	var duration=1000;
	var liHeight=20;	// px
	var liCount=jQuery(".news ul li").size();
	var liMaxTop="-"+(liHeight*(liCount-1))+"px";
	
	function newsScroller()
	{
		jQuery(".news ul").animate({marginTop:"-=20px", opacity:"0.3"},
			   duration,
				 function(){
					 if(jQuery(this).css("marginTop")==liMaxTop) jQuery(this).animate({marginTop:"0px",opacity:"0.3"},duration).animate({opacity:1}).animate({marginTop:"-=0px"},delayTime);	
					 newsScroller();
				} 
				).animate({opacity:1}).animate({marginTop:"-=0px"},delayTime);
	
	}
	newsScroller();
	// expand form 
	jQuery("#expandForm").click(function()
	{
			
			if (jQuery(this).attr("class")=="expandForm")
			{			
				jQuery(this).html("Hide Form").removeClass().addClass("collapseForm");
				jQuery(this).parent().stop().animate({height:"710px"}, {duration:400})
			}
			else
			{			
				jQuery(this).html("Click here now").removeClass().addClass("expandForm");; 
				jQuery(this).parent().stop().animate({height:"360px"}, {duration:400})
			}
	});
	
	// accordion
	
	// add bullets
	jQuery(".accordion > li").each(function(i)
	{
		jQuery(this).find("a").prepend("<span class='bullet'></span>");
	});
	
	
	// click
	jQuery('.accordion').accordion({
			event: 'click',
			header: ".heading",
			autoHeight:false,
			    alwaysOpen: false, 
			selectedClass:"active",
			animated:'bounceslide'
		});
		
		
 
 	
	// onclick show information
	jQuery(".products li").click(function()
	{
		jQuery(".products_description").fadeOut().html(jQuery(this).find(".content").html()).fadeIn();
		jQuery("#products_image").fadeOut().attr("src",jQuery(this).find(".content").attr("title")).fadeIn();
	});
	
	
	
	
	// script for carousel
	jQuery(".products").scrollable(
	{
			size:3, 
			speed:800,
			interval:5000,
			loop:true,
			
			onBeforeSeek: function() { 
				this.getItems().fadeTo(300, 0.5);         
			}, 
			onSeek: function() { 
				this.getItems().fadeTo(300, 1);  
			}
	});
	
	
	
	jQuery("#quickContactForm").submit(function()
											  {
												  	// make the form almost invisible but just leave a trace of it.
												  	jQuery(this).animate({opacity:0.04},1000);
													
													// bring up the message/progress box
												  	//jQuery("#quickContactMessage").html("<center><br><br><br><br><img src='includes/images/progress1.gif'><br><br>Sending your message...</center>")
												  	//jQuery("#quickContactMessage").fadeIn();
													
													jQuery(".progressBox .msg")
													.html("<img src='includes/images/progress2.gif' align='absmiddle' hspace='10px' />Sending your message...")
													.parent().fadeIn();
													
													// submit the form 
													jQuery.post("includes/functions/ajax.php",jQuery(this).serialize(),function(str)
													{
														if (str=="")	
														{
															jQuery(".progressBox .msg")
															.html("<h2>Thank you!</h2> Your message was successfully sent. <br>Our representatives will be in touch with you shortly.")
															.parent().fadeIn();

//jQuery("#quickContactMessage").html("<center><br><br><br><h3>Thank you!</h3> Your message was successfully sent. <br>Our representatives will be in touch with you shortly.<br><br><br></center>")						
														
															// stay for 10 seconds
															setTimeout(function()
																				{
															
															// Bring the form back to life
															jQuery("#quickContactForm").animate({opacity:1},100);
															
															// ask the message/progress box to disappear
															//jQuery("#quickContactMessage").fadeOut(0);
															jQuery(".progressBox").fadeOut();	
															
															jQuery("#expandForm").trigger("click");
															
																				},10000);
 														
														}
														else
														{
													jQuery(".progressBox .msg")
															.html("<h2>Oops...!</h2>There were some issues while sending your message:<br>"+str+"<br><br><a href='#' id='quickContactClose'>Let me correct!</a>").parent().fadeIn();
															//	jQuery("#quickContactMessage").html("<center><h3>Oops...!</h3>There were some issues while sending your message:<br>"+str+"<br><br><a href='#' id='quickContactClose'>Let me correct!</a><br></center>");						
														
														jQuery("#quickContactClose").click(function()
																									{
																										// Bring the form back to life
												  														jQuery("#quickContactForm").animate({opacity:1},2000);
																										
																										// ask the message/progress box to disappear
																									jQuery(".progressBox").fadeOut();
																									
																									//	jQuery("#quickContactMessage").fadeOut();
																										return false;
																										
																									});
														}
														
													});
																								
																								
													
													
													
												
													
													
													return false;
											  });
 
	
	
	

	jQuery(".right_buttons #downArrow").click(function()
													  {
														  	jQuery.scrollTo( jQuery("#portfolio_container"), 2000/*, {easing:'elasout'}*/ ); 
													  });
	
	// Get Portfolio Items

	function getPortfolioProjects(cat_code,page,keyword)
	{
		
	jQuery("#cat_code").attr("value",cat_code);	
	
	jQuery.post("includes/functions/ajax.php",{mode:"get_portfolio_items",cat_code:cat_code,page:page},function(str)
										   {
											 
											   var items=str.split("~[RS]~");	// get item rows 
											 
											   var pagingInfo=items[0].split("~[CS]~");	
											   
											   
											   jQuery("#portfolio_container  .msgBox").html(pagingInfo[0]);
											   
											   jQuery("#portfolio_container  dl.paging").html("");
											   
											   jQuery("#portfolio_container  dl.paging").aqPaging({
											   current: pagingInfo[2], pages: pagingInfo[1], flip: false, cb: function(p)
												{ 
 													getPortfolioProjects(jQuery("#cat_code").attr("value"),p,"");
												} 
											  });
											 
											
											
											 jQuery("#portfolio_container ul li").remove();
											 // because the first row contains paging info start looping from the second
											 for(i=1;i<items.length;i++)
											 {
												 var item=items[i].split("~[CS]~");	
												jQuery("#portfolio_container ul").append("<li project_id='"+item[0]+"'><div class='info'><strong>"+item[1]+"</strong><br /></div><div class=overlay></div><img class=progress src='includes/images/progress1.gif'><img class=project_thumb src='manager/uploads/projectSnapshots/big_"+item[4]+"'  /></li>").find(".project_thumb").load(function()																																																																																																	{
													jQuery(this).fadeIn().parent().find(".progress").hide();	
											
											
											
											
											
											
											
											
											
											
											
											}).error(function()
											{
												jQuery(this).attr("src","includes/images/nopreview.jpg").parent().find(".progress").hide();
											});
											 }
											 
											 
											 									// Portfolio : on mouseover option
					jQuery("#portfolio_container ul li img").mouseover(function()
																	  {
																		jQuery(this).parent().find("div.overlay").fadeIn();  
																		jQuery(this).parent().find("div.info").fadeIn();  
																		
																	  });
					jQuery("#portfolio_container ul li div.info").mouseout(function()
																	  {
																		
																		jQuery(this).parent().parent().find("div.info").fadeOut("fast");  
																		jQuery(this).parent().parent().find("div.overlay").fadeOut("fast");  
																		
																	  });
					
					jQuery("#portfolio_container ul li div.info").click(function()
																	  {
																		 jQuery(this).fadeOut("fast");  
																		 jQuery(this).parent().find("div.overlay").fadeOut("fast");  
																		  
														
														var project_id=jQuery(this).parent().attr("project_id");
														
														jQuery.post("includes/functions/ajax.php",{mode:"load_portfolio_item_details",project_id:project_id},function(str)
																		  { 
																		  		var items=str.split("~[RS]~");	
																				var item=items[0].split("~[CS]~");
																				
																	jQuery(".project_details").attr("project_id",item[0])
																	.find(".project_title").html(item[1])
																	.parent().find(".project_mockup_url").html("Mockup URL: <a href='"+item[2]+"'>"+item[2]+"</a>")
																	.parent().find(".project_live_url").html("Live URL: <a href='"+item[2]+"'>"+item[2]+"</a>")
																	.parent().find(".project_description").html(item[5])
																	.parent().find(".project_screens img").attr("src","manager/uploads/projectSnapshots/thumb_"+item[4]);
																		
																				
																				
																				
																		  });
				
														 
														jQuery(".project_details").slideUp().slideDown()
														 .find(".project_screens")
														 .find(".middle_content div.progress")
														 	.show()
														 	.find("img")
															.load(function(){
																			 	jQuery(this).fadeIn();
																			 })
														 .parent().parent().parent().slideDown("slow");
														
														 
 													   	 /*jQuery(".project_details").slideUp().slideDown()
														 .find(".project_screens")
														 .find(".middle_content div.progress")
														 	.show()
															.html("<img src='http://vocso.com/includes/images/main.jpg' border=0px>")
														 	.find("img")
															.load(function(){
																			 	jQuery(this).fadeIn();
																			 })
														 .parent().parent().parent().slideDown("slow");
														*/
														 
														  jQuery.scrollTo( jQuery(".bodyleftinner"), 2000/*, {easing:'elasout'}*/ ); 
														 
														 
													  });

			
											 
											 
											 
										   });

 	}
	
	getPortfolioProjects("",1,"");
	
	
	jQuery("#portfolioCategories a").click(function()
													{
 														getPortfolioProjects(jQuery(this).attr("cat_code"),1,"");
														
														if (jQuery(this).attr("cat_code").length>5) return false;
 													});
	


function showFormError(obj,msg)
{
 	var name=jQuery(obj).attr("name");	
 	jQuery(obj).parent().find("#"+name+"_error").remove();
	jQuery(obj).parent().prepend("<span id='"+name+"_error' class='error_span'>"+msg+"</span>")
				.find("#"+name+"_error").fadeIn();
	jQuery(obj).mouseover(function()
	{
			jQuery(obj).parent().find("#"+name+"_error").fadeOut("fast");																																																	    });	
	jQuery(obj).parent().find("#"+name+"_error").mouseover(function()
	{
			jQuery(obj).parent().find("#"+name+"_error").fadeOut("fast");																																																	    });	
	
	jQuery.scrollTo( jQuery(obj).parent().parent(), 500); 
}


function validateFormSteps(step_id)
{
	var validated=true;
 	
	switch(step_id)
	{
			case "1":
				var obj=jQuery("ul.raqbox li#"+step_id+" [name='rfq_input_project_details']");
				if (jQuery(obj).val().length<50) 
				{
 					showFormError(obj,"Enter the details in atleast 50 characters");
					validated=false;
				}
				break;
			case "2":
				var obj=jQuery("ul.raqbox li#"+step_id+" [name='rfq_input_project_other_details']");
				if (jQuery(obj).val().length<50) 
				{
					showFormError(obj,"Enter the details in atleast 50 characters");
					validated=false;
				}
				break;
			case "3":
				var obj=jQuery("ul.raqbox li#"+step_id+" [name='rfq_input_name']");
				if (jQuery(obj).val().length<3) 
				{
					showFormError(obj,"Enter your name");
					validated=false;
				}
				var obj=jQuery("ul.raqbox li#"+step_id+" [name='rfq_input_name_business']");
				if (jQuery(obj).val().length<3) 
				{
					showFormError(obj,"Enter your company/business name");
					validated=false;
				}
				var obj=jQuery("ul.raqbox li#"+step_id+" [name='rfq_input_email']");
				
				
				var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
 
 				if (!emailPattern.test(jQuery(obj).val())) 
				{
					showFormError(obj,"Enter your email address correctly");
					validated=false;
				}
				break;
			break;
	}
	return validated;
}




	jQuery("ul.raqbox li input.btn_raq_next").each(function(i)
															{
															 jQuery(this).click(function()
															 {
																 var step=jQuery(this).parent().parent().parent().find("li.active");
  																 var validated=validateFormSteps(jQuery(step).attr("id"));
																 
															
																 if (jQuery(step).attr("id")<=2 && validated)
																 {
 																	 jQuery(step).fadeOut("slow").removeClass("active").next("li:eq(0)").fadeIn("slow").addClass("active");
																 	 jQuery.scrollTo( jQuery(".bodyleftinner"), 2000/*, {easing:'elasout'}*/ ); 
 																 }
																 return false;
															 });
															});
	
	jQuery("ul.raqbox li input.btn_raq_previous").each(function(i)
															{
															 jQuery(this).click(function()
															 {
																 var step=jQuery(this).parent().parent().parent().find("li.active");
																 if (jQuery(step).attr("id")>=1)
																 {
 																	 jQuery(step).fadeOut("slow").removeClass("active").prev("li:eq(0)").fadeIn("slow").addClass("active");
																 
																 	 jQuery.scrollTo( jQuery(".bodyleftinner"), 2000/*, {easing:'elasout'}*/ ); 
 																 }
																 return false;
															 });
															});



jQuery("ul.raqbox input.btn_raq_submit").click(function()
														{
															var validated=validateFormSteps("3");
															if (validated)
															{
																	
																jQuery(".progressBox .msg").html("<img src='includes/images/progress2.gif' align='absmiddle' hspace='10px' />Sending quote request...").parent().fadeIn();
														    	jQuery.post("includes/functions/ajax.php",jQuery("#raq_form").serialize(),function(str)
																	 {
																		jQuery(".progressBox .msg").html("<h2>Congratulations!</h2>We've successfully received your quote request. <br>We will be in touch with you within next 1 business day!").parent().click(function(){jQuery(this).fadeOut();});
																	 });	
															}
															return false;
														});








	
});
