	$(document).ready(function() {
							   
		$('#submit').click(function() {
			$('#newsletter_message').html('<img src="/images/preloader.gif">');
			$.post('/newsletter.php', $("#newsletter").serialize(), function(data) {
				$('#newsletter_message').html(data);
			});
			return false;
		});
		
		//Default Action
		$(".tab_content").hide(); //Hide all content
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content
		
		//On Click Event
		$("ul.tabs li").click(function() {
			$("ul.tabs li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content").hide(); //Hide all tab content
			var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active content
			return false;
		});

 		$(".img").hover(
			function() { $("."+$(this).attr('id')).css({ display: "block" }); },
			function() { $("."+$(this).attr('id')).css({ display: "none" }); }
		);

 		$(".pic").click(
			function() { 
				var height =$(document).height()+"px";
				var width = $(document).width()+"px";
				$(".modal").css({ display: "block", height:height, width:width }); 
				var left = parseInt(($(document).width()/2)-250);
				$(".pictures").css({ left: left-100 +'px'}); 
				$(".pictures").show('slow'); 
			
			}
		);

 		$("#dsc").click(
			function() { 
				var height =$(document).height()+"px";
				var width = $(document).width()+"px";
				$(".modal").css({ display: "block", height:height, width:width }); 
				var left = parseInt(($(document).width()/2)-250);
				$(".dsc").css({ left: left+'px'}); 
				$(".dsc").show('slow'); 
			
			}
		);
 		$("#size").click(
			function() { 
				var height =$(document).height()+"px";
				var width = $(document).width()+"px";
				$(".modal").css({ display: "block", height:height, width:width }); 
				var left = parseInt(($(document).width()/2)-250);
				$(".size").css({ left: left+'px'}); 
				$(".size").show('slow'); 
			
			}
		);

		$(".img").mousemove(function(e) {
			var mousex = e.pageX + 10;
			var mousey = e.pageY + 5;
			
			if($(this).attr('id') == 'bifocal' || $(this).attr('id') == 'progressive' || $(this).attr('id') =='framesize'){
				var mousex = e.pageX - 500;
				var mousey = e.pageY - 100;
			}else{
				var mousex = e.pageX + 10;
				var mousey = e.pageY + 5;
			}
			
			$("."+$(this).attr('id')).css({  top: mousey, left: mousex });
		});
		
		$(".to-tal").change(function() {
			calcutalteTotal()
		});
		$("#tell_friend").click(
			function() { 
				var height =$(document).height()+"px";
				var width = $(document).width()+"px";
				$(".modal").css({ display: "block", height:height, width:width}); 
							
				var left = parseInt(($(document).width()/2)-250);
				$(".mymailer").css({ left: left+'px'}); 
				$(".mymailer").fadeIn("slow"); 
			}
		);
		
		$("#close").click(
			function() { 
				var height =$(document).height()+"px";
				var width = $(document).width()+"px";
				$(".mymailer").fadeOut("slow"); 
				$(".modal").fadeOut(1000); 
				$(".os").fadeOut("slow"); 
				$(".OOS").fadeOut(1000); 

			}
		);
		
		$(".close").click(
			function() { 
				var height =$(document).height()+"px";
				var width = $(document).width()+"px";
				$(".mymail").fadeOut("slow"); 
				$(".modal").fadeOut(1000); 
				
			}
		);
			
		
		
		function calcutalteTotal(){
			var val 			= $("#original_price").attr('value');
			var polarize		= 3.95;
			var value 			= 0;
			var txt 			= '';
			var res 			= '';
			var total 			= 0;
			$('.to-tal').each(function(index) {
				$name = $(this).attr('name');
				$option = $("select[name='"+$name+"'] option:selected").val();
				
				if('clip_polarized' == $name ){
					value = parseFloat($("select[name='"+$name+"'] option:selected").val());
					val = parseFloat(val) + (value * parseFloat(polarize));
				}else{
					txt = $("select[name='"+$name+"'] option:selected").text();
					res = txt.match(/\(\$(.*)\)/);
					if(res == null){
						val = parseFloat(val)+parseFloat(0);
					}else{
						val = parseFloat(val)+parseFloat(res[1]);
					}
					
				}

				
			 });
			
			total = val.toFixed(2);
			$(".val").html('Price $'+total);
			$("#total").val(total);

		}
		
		
		$("#oos_request").validate({
			debug: false,
			rules: {
				name: "required",
				qty: "required",
				email: {
					required: true,
					email: true
				},
			},
			messages: {
				name: "Name is Required.",
				qty: "Quantity is Required.",
				email: "Your email Address is Required.",
			},
			submitHandler: function(form) {
				$('#results').fadeIn(1000);
				$('#results').html('<img src="/assets/images/preloader.gif"><div class="status loading">Sending ...</div>');
				$.post('/templates/lenses/email.php', $("#oos_request").serialize(), function(data) {
					$('#results').html(data);
					$('#results').fadeOut(5000);
				});
				
			}
		});
		

		$("#myform").validate({
			debug: false,
			rules: {
				name: "required",
				price: "required",
				descr: "required",
				prodname: "required",

				email: {
					required: true,
					email: true
				},
				email2: {
					required: true,
					email: true
				}
				
			},
			messages: {
				name: "Name is Required.",
				email: "Your email Address is Required.",
				email2: "Your frieds Email is Required.",
			},
			submitHandler: function(form) {
				$('#results').fadeIn(1000);
				$('#results').html('<img src="/assets/images/preloader.gif"><div class="status loading">Sending ...</div>');
				$.post('/templates/glasses/email.php', $("#myform").serialize(), function(data) {
					$('#results').html(data);
					$('#results').fadeOut(5000);
				});
			}
		});
		
		$('.loading').html('<img src="/assets/images/preloader.gif" ><br /> Loading request...');
		$.get('/fav.php', { action:'load'} , function(data) {
			$('.data').html(data);
			$('.loading').html('');
		});
 	});
		
	function addfav(val){
		$('.loading').html('<img src="/assets/images/preloader.gif" ><br /> Loading request...<br /><br /><br />');
		$.get('/fav.php', { prod:val} , function(data) {
		  $('.emptyfav').remove()
		  $('.data').prepend(data);
		  $('.loading').html('');
		});
	}
	
	function deleteFav(val){
		$('.fav'+val).slideUp('slow');
		$.get('/fav.php', { prod:val,action:'delete'} , function(data) {
			 if(data <=0 ){
				 	$('.data').html('<span class="red emptyfav" style="text-align:center; margin-left:40px">Favorite is empty</span>');
			 }
		});

	}
	

