//FUNCTIUN TO POP UP WINDOW
function open_win(url_add)
{
   window.open(url_add, "mywindow","menubar=0, scrollbars=1, location=0, resizable = no,  width=350, height=250"	);
}


//FUNCTION TO VALIDATE EMAIL
function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   }else{
	  return true;
	}
}

// JavaScript Document
$(document).ready(function(){
	
	//FOR HOME PAGE HAS CLASS
	if($('body').hasClass('hascycle')){
		$('#innerbanner').cycle({
			fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});
	}
	
	//FOR HOME PAGE HAS CLASS
	if($('body').hasClass('hascyclebanner')){
		$('#brandsslideshow').cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			speed:3000,
			timeout:6000
		});
	}
	
	
	
	
	if($('a').hasClass('collection_images')){
		$("a.collection_images").fancybox({
		
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	false
		
		});
	}
	
	
	
	
	//IF USING SLIDER
	if($('div').hasClass('rangeContainer')){
		// Slider
		$('#slider').slider({
						range: true,
						min: 0,
						max: 10000,
						values: [500, 3000],
						slide: function(event, ui) {
							$("#amount").val('$' + ui.values[0] + ' - $' + ui.values[1]);
						}
	
		});
				
		$("#amount").val('$' + $("#slider").slider("values", 0) + ' - $' + $("#slider").slider("values", 1));
	}

	
	//CURRENT COLLECTION
	
	img2 = new Image(); 
	img2.src = "../images/close-collection.png"; 
	
	$(".currentcollection   li:nth-child(6n)").addClass("notitle");
	$(".currentCollectionBtn img").attr('src', 'images/close-collection.png');
	//$(".currentcollection   li:gt(3)").addClass("hideElement");

	$(".currentCollectionBtn").toggle(
      function () {
		$(".currentcollection  li:gt(3)").fadeIn("slow");
		$(".currentCollectionBtn img").attr('src', 'images/close-collection.png');

      },
      function () {
       	$(".currentcollection  li:gt(3)").fadeOut("slow");
		$(".currentCollectionBtn img").attr('src', 'images/see-all.png');
		
      }
    );
	
	
	//FOR LOGO COLLECTION
	$(".logocollection  li:nth-child(4n)").addClass("notitle");


		
	// FOR THE SUBSCRIBE BTN
	$("#subcribebtn[rel]").overlay({

		// some mask tweaks suitable for modal dialogs
		mask: {
			color: '#fff',
			loadSpeed: 200,
			opacity: 0.8
		},

		closeOnClick: true,
		
		 onBeforeLoad: function(event, tabIndex) {
			$("#msg").empty();
			$("#email").show();
			$("#button").show();
			$(".frontoffield").show();
			$("#email").val("");
		}
		
	});  //END OF OVERLAY 
	
	
	$("#contactusbtn[rel]").overlay({
		
		// some mask tweaks suitable for modal dialogs
		mask: {
			color: '#fff',
			loadSpeed: 200,
			opacity: 0.8
		},

		closeOnClick: true,
		
		 onBeforeLoad: function(event, tabIndex) {
			$("#msg").empty();
			$("#email").show();
			$("#button").show();
			$(".frontoffield").show();
			$("#email").val("");
		}
	
	
	});


	img = new Image(); 
	img.src = "../images/popup-bt-btn.jpg"; 

	$("#button").mouseover(function(){
		$(this).css("background-image", "url(images/popup-bt-btn.jpg)");  		
	}).mouseout(function(){$(this).css("background-image", "url(images/popup-bt-top.jpg)");});
	

	
		//CliCk button
	$("#button").click(function(){				   
			
			var email = $("#email").val(); 
			var emailok = validate(email);
			
			var firstname = $("#firstname").val(); 
			var lastname = $("#lastname").val();
			var Language = $("#Language").val();
			
			var data ={email:email,firstname:firstname,lastname:lastname,Language:Language};
			
		   	if(emailok==true){
				
				$.ajax({
					type: 'GET',
					url: "ajax/to-cake-mail.php",
					data: data,
					success: function(response) { /*alert(response)*/ },
					error: function(xhr, type, exception) { /*alert("Error: " + type);*/ }
				})
				
				
				//$(this).hide();
				$("#msg").empty();
				$("#msg").append("Thank you. You are now register to Corkwick e-List. An email has been sent to confirm your subscription.");
				$(".textbox").val("");
				
				return false;
				//triggers.overlay().close();
			}
			
			if(emailok==false){
				$("#msg").empty();
				$("#msg").append("<b>Error - Invalid Email Address</b>");
			}
	});



	//POP UP FOR LEGAL INFO
	$(".legalinfoLink").click(function(){	
		 open_win("legal-info.php");
	})	
	


}); // end of ready() function


