// Modal window - login
$(document).ready(function() {
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		e.preventDefault();
		
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width()-16;
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		$('#mask').fadeIn(300);
		$('#mask').fadeTo("fast", 0.8);
		
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		$(id).fadeIn(1000); 
	
	});
	
	$('.window .close').click(function (e) {
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});
	
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});	
}); 

function submitPage(page){
	$('input[name=page]').attr("value", page);
	$('form[name=form_advanced_search]').submit();
	return false;
}

$(document).ready(function() {	
	$('.link-title').mouseover(function() {
		var link_name = $(this).attr("name");
		
		$("#links_titles").find('.link-title').each(function (i) {
	        if ($(this).attr("name") == link_name){
	        	$(this).addClass("selected");
	        	
	        	$('.link-description.' + link_name).show();
	        	
	        }else{
	        	$(this).removeClass("selected");
	        	var tmp = $(this).attr("name");
	        	$('.link-description.' + tmp).hide();
	        }
	    });
	});
	
	$('.link-description').mouseleave(function() {
		$('.link-description').hide();		
	});
});


$(document).ready(function() {	
	// Products gift options
	$('input[name=gift_package]').click(function() {
		var checkedInput = $(this).attr("id");		
		$(".gift-options").find('input[type=checkbox]').each(function (index, currentElem) {			
			if ($(currentElem).attr('id') != checkedInput){
				$(currentElem).attr('checked', false);
			}else{
				$('input[name=gift_package_selected]').attr("value", checkedInput);
			}
	    });
	});
	
	//Promotion popup close
	$('.p-close').click(function() {
		$("div[class=overmask]").hide();
		$("div[class=popup]").hide();
		return false;
	});	
});


// === SITE ALERTS ===
$(document).ready(setFade);
function setFade(){
	if ($('.alert-block').css('display') == "block"){
		setTimeout('$(".alert-block").fadeOut(1000);',3000);
	}
}
