﻿/**
 * Default javascript file for Campina.nl website
 *
 * @copyright eFocus (http://www.efocus.nl)
 * @author Klaas Dieleman
 * @author Lee Boonstra
 * @since apr 2011
 * @require jQuery 1.5.1 (http://www.jquery.com)
 */


/**
 * Executed when DOM structure has loaded
 */
$(window).ready(function() {
	
	centerFooter();
	
	if($('div.footerwrapper div.about_us').length > 0) initSlidingFooter();
	setCatLinks('div.category ul li.row');
	initExternalLinks();
});

/**
 * Executed when all resources have loaded and page has fully rendered
 */
$(window).load(function() {
	
	// IE6 transparency
	var blank_img = '/fileadmin/templates/img/blank.gif';
	$('a.headerlogo img').supersleight({shim: blank_img});
	$('ul.products').supersleight({shim: blank_img});
	$('ul.products').supersleight({shim: blank_img});
	$('div.home_block').supersleight({shim: blank_img});
	$('div.wrapper div.block span.top').supersleight({shim: blank_img});
	$('span.packshots').supersleight({shim: blank_img});
	
	new Pushbox($('ul.home_slideshow li'), {
		'navigation'	: false,
		'interval'		: 5,
		'freezeonhover'	: false
	});
});

$(window).resize(function() {
	centerFooter();
});

function centerFooter() {
	if ($('div.footerwrapper div.footer')) {
		$('div.footerwrapper div.footer').css('left', ($(window).width()-$('div.footerwrapper div.footer').width())/2, $(window).width(), $('div.footerwrapper div.footer').width());
	}
}

/**
 * initializes sliding footer on homepage
 * @author Rocco Janse, rocco@efocus.nl
 */
function initSlidingFooter() {

	$('div.footerwrapper a.about_close').fadeOut(0);
	
	$('a.about_open').click(function() {
		openFooter();
	});
	
	$('a.about_close').click(function() {
		closeFooter();
	});
	
	if(location.hash.indexOf('over-ons') != -1) {
		openFooter();
	}

}

/**
 * opens the footer and toggles the open/close buttons
 * @author Rocco Janse, rocco@efocus.nl
 */
function openFooter() {
	$('div.footerwrapper a.about_close').fadeIn();
	$('div.footerwrapper a.about_open').fadeOut();
	$('div.footerwrapper div.footer').fadeOut(1);
	$('div.footerwrapper').animate({
		'margin-top': -700,
		'height': 2350
	},{
		complete: function() {
			$('div.footerwrapper div.footer').fadeIn(1);
		}
	});
}

/**
 * closses the footer and toggles the open/close buttons
 * @author Rocco Janse, rocco@efocus.nl
 */
function closeFooter() {
	$('div.footerwrapper a.about_close').fadeOut();
	$('div.footerwrapper a.about_open').fadeIn();
	$('div.footerwrapper div.footer').fadeOut(1);
	$('div.footerwrapper').animate({
		'margin-top': -103,
		'height': 50
	},{
		complete: function() {
			$('div.footerwrapper div.footer').fadeIn(1);
		}
	});
}

/**
 * get all category links, and make the whole item clickable
 * @param strItems = list item with links
 * @copyright eFocus (http://www.efocus.nl)
 * @author Lee Boonstra
 * @since apr 2011
 */
function setCatLinks(strItems){
	var arrItems = $(strItems);
	if(arrItems.length > 0){
		arrItems.each(function(){
			var arrLink = $(this).find('a');
			$(this).click(function(){
				window.location.href = arrLink[0];
			})	
		});
	}
}

/**
 * Opens links with rel=external or class=external attribute in a new window/tab without the deprecated target attribute
 * @author Klaas Dieleman
 */
function initExternalLinks() {
	jQuery('a[rel~=external], a[class~=external]').click(function(e) {
		e.preventDefault();
		window.open(jQuery(this).attr('href'));
	});
}
