// JavaScript Document

$(document).ready(function() {
	
	/* START ROLLOVER */
	var cache = [];
	
	$("img.roll, input.roll").each(function() {
		//let's preload
		var cacheImage = document.createElement('img');
		cacheImage.src = this.src.replace(/_off([_\.])/, '_on$1');
		cache.push(cacheImage);
	});
	
													 
	$("img.roll, input.roll").hover(function(){
		//alert(this.src);
		this.src=this.src.replace(/_off([_\.])/, '_on$1');
	},
	function(){
		this.src=this.src.replace(/_on([_\.])/, '_off$1');
	});
	
	/* END ROLLOVER */
	
	
	$(window).resize(resize_background_image_now());
	/*
	$(".store").fancybox({
		'width'				: 975,
		'height'			: '80%',
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});*/
});


/* START DROP DOWN*/
/*
$(function(){
		var navTimers = [];
    
		$("div#shoppingcart_wrapper").hover(function(){
				var id = jQuery.data(this);
				var $this = $( this );
				$('div:first',$this).addClass('bt_shopping_cart_hover');
				
				navTimers[id] = setTimeout( function() {  
					//alert(id);
					$('div.shopping_cart_open_wrapper').css('display', 'block'); 
					navTimers[id] = "";  
				}, 100 );
    }, function(){
        var id = jQuery.data(this);
				var $this = $( this );
				$('div:first',$this).removeClass('bt_shopping_cart_hover');
				if (navTimers[id] != "") {
					clearTimeout(navTimers[id]);
				}
				$('div.shopping_cart_open_wrapper').css('display', 'none'); 
    });
		
});*/
/* END DROP DOWN */

// un background toujours visible, dependant la largeur et hauteur de la page

function resize_background_image_now() {	
	var bg = $('div.bg_image > img');
	var ratio = 3/2;
	
	bg.attr('width', $(window).width());
	bg.attr('height', $(window).width() / ratio);
	
	if (parseInt(bg.attr('height')) < $(window).height()) {
		bg.attr('height', $(window).height());
		bg.attr('width', $(window).height() * ratio);
	}
}

function validateNewsletter() {
	
	if ($('#uylrjd-uylrjd').val() == "") {
		alert('Please provide your email address');
		return false;
	}
	if (emailcheck($('#uylrjd-uylrjd').val())==false) {
		alert("Please provide a valid email address")
		return false;
	}
}

function emailcheck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		 return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		 return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
			return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
			return false
	 }
	
	 if (str.indexOf(" ")!=-1){
			return false
	 }

	 return true					
}

