$(document).ready(function(){ 
	Cufon.replace("#menuList > li > a, h3, .submenu li, h2, h1", {hover: true});
	
	//Load images
	$('#productList a').children('img').each(function() {
		// Hide the image
		$(this).hide().stop();
		
		// Create the image resource
		var $t  = $(this);
		var img = new Image();
		img.onload = function() {
			$t.fadeIn();
			$t.siblings('span').fadeIn();
		}
		
		// Load the image
		img.src = $(this).attr('src');
	});

	//input hints
	$('input[title!=""], textarea[title!=""]').inputHint();
	
	// Apply fancybox
	$('a.fancy, a.media').fancybox({
		overlayColor: '#000',
		overlayOpacity: 0.8,
		titlePosition: 'inside'
	});
	// Add some reflection to product-images
	$(".productList img").reflect({
		opacity: 0.33
	});
	
	// Change state of price-block when hovering over the image
	$('#productList a.image').hover(
		function(){
			$(this).siblings('a').addClass('priceHover')
		}, 
		function(){
			$(this).siblings('a').removeClass('priceHover')
		}
	);
	
	$('a.newsletter').click(function(){
		newsletterForm();
		return false;
	});
	
	//attach newsletter action to form on homepage
	$('#form_newsletter_home').submit(function(){
		//open the newsletter form
		newsletterForm($('#newsletter_email').val());
		
		//don't submit
		return false;
	});
	
	//open subscription in an iframe, and set the default value for the email
	//field	
	function newsletterForm(_email) {
		var $href = jQueryBaseHref+'/newsletter/subscribe?iframe=true';
		if (typeof(_email) != 'undefined') $href += '&email='+_email;
		$.fancybox(
			{
				'href'				: $href,
	        	'autoDimensions'	: false,
	        	'type'    	     	: 'iframe',
	        	'padding'         	: 5,
				'width'         	: 500,
				'height'        	: 450,
				'transitionIn'		: 'easeInExpo',
				'transitionOut'		: 'easeOutExpo',
				'overlayOpacity'	:  0.6,
				'overlayColor'		: '#1a1005'
			}
		);
	}
	
	// Cycle homepage pictures
	$(".cycleWrapper").cycle();
	
	// Navigation
    $('ul.sf-menu').superfish({
    	autoArrows: false,
        animation: {opacity:'show',height:'show'}  // fade-in and slide-down animation 
    }); 
    
    // Add a layer when user clicks on navigation
    $("#scroll").width($('#container').width());
	$("#scroll").height($('#container').height());
    
	$('#scroll').fadeOut(700, function() {
		$(this).css({
		    opacity: 0,
		    bottom: '0px',
		    left: '0px',
		    height: '0px'
		});
	});
	
	$('#menu.animate a').click(function(e) {
		e.preventDefault();
		var href= $(this).attr('href');

	  $('#scroll').animate({
		  opacity:1,
		  height: $('#container').height()
	  }, 700, function() {
		  window.location = href;
	  });

	});
	
	/* var $adCookie = $.cookie("open-houses");
	if (!$adCookie) {
		$.cookie("open-houses", true);
		$("#open-houses").click();
	} */
}); 
