/* Author: Luca Fregoso */

function hideMenu(){
	$("#related-products").stop().animate({width:"0"},500);
	$("#main_header,#main_footer").slideUp(450,function(){
	    checkWrapperSize(); 
	    if($("watermark").length == 0){
		var $_src = $(".main-menu-icon.active>img").attr("src");
		$("<img>").attr("class","watermark").attr("src",$_src).css({"position":"absolute","top":"20px","left":"20px","display":"none"}).prependTo("#wrapper").fadeIn("standard");
	    }
	});
}
function showMenu(){
	$(".watermark").fadeOut("fast",function(){
	    $(this).remove();
	});
	$("#main_header,#main_footer").slideDown(450,function(){
	    checkWrapperSize(); 
	    $("#related-products").stop().animate({width:"170px"},500);
	});
}


function checkWrapperSize(){
	var marginBottom = $('#main_footer').height();
	if($('#main_footer').css('display')=='none')
	    marginBottom = 0;
	var marginTop = $('#main_header').height();
	if($('#main_header').css('display')=='none')
	    marginTop = 0;
	$('#wrapper').css({'top':marginTop,'bottom':marginBottom,'height':($(window).height() - marginTop - marginBottom),'max-height':($(window).height() - marginTop - marginBottom) });
}
$(window).load(function(){
    $(".external").attr('target', '_blank');
    checkWrapperSize();
    Cufon.replace('.fntrplc');
}).resize(function(){
    checkWrapperSize();    
});

function fbs_click() {
        u=location.href;
        t=document.title;
        window.open('http://www.facebook.com/sharer.php?u=' +
             encodeURIComponent(u) +
             '&t=' +
             encodeURIComponent(t),
             ' sharer', 'toolbar=0, status=0, width=626, height=436');
        return false;
}
$("#NewsletterIndexForm").live("submit",function(e){
	e.preventDefault();
	$.ajax({
		url:"/newsletter",
		data:$(this).serialize(),
		dataType: 'json',
		success:function(data){
			if(data.success==true){
				$("#NewsletterEmail").css('color','#669966');
				alert('Thank you for subscribing to our Newsletter');
			}
		}
	});
});

$(document).ready(function () {
	$(".main-menu-icon")
		.not('.active')
			.hover(function(){
				$(this).find("span.hover_tag").slideToggle();
			})
			.end()
		.filter('.active')
			.find("span.hover_tag")
			.css('display','inline');
		
	$(".share-facebook-link").click(function(e){
		e.preventDefault();
		fbs_click();
	});
});

