/**
 * Site global JS file
 *
 * @author PG
 */

	/*
	 * Set debug mode
	 */
		LibMan.setDebugMode(false);
 

	/**
	 * on Dom ready functionality
	 */
		$(document).ready(function() {

			// debug
			LibMan.debug('JS Library loaded');
		
			// add an extra class to the <body> element for JS-only styling
			$("body").addClass("js");
			
			
			// insert template image overlay for layout testing
			// Development only, remove for live
			var gridSettings = {
				imgExt: "jpg",
				gridPos: "center top"
			};
			//$.gridOverlay(LibMan.path + "../../_templates/", gridSettings);
			

			// open links in a new window
			links.init('a[rel="external"]');


			// print links in footer
			printFootnoteLinks.init("content","wrapper");
			
			
			// toggle default form text
			toggleDefaultText.init('input.default');
			
			
			// Fix PNGs for IE6
			$('img.png-24, .png-fix').supersleight({shim: LibMan.path + '/lib/png/x.gif'});
			

			// display product promo blocks on hover
			if (!LibMan.isMSIE) {
				$("div.product.promo-block em, div.product.promo-block span.price, body#home div.hero em").css({display:"block", opacity:0});
			}
			$("div.product.promo-block, body#home #hero-container").hover(
				function(){ 
					var $els = $(this).find("em, span.price");
					if (!LibMan.isMSIE) {
						$els.stop().animate({ opacity:1}, 250);
					} else {
						$els.css({display:"block"});
					}
					
				},
				function() {
					var $els = $(this).find("em, span.price");
					if (!LibMan.isMSIE) {
						$els.stop().animate({ opacity:0 }, 250);
					} else {
						$els.css({display:"none"});
					}
				}
			);
			
			// hide all alt tags (for IE)
			if (LibMan.isMSIE) {
				$("#content img").attr('title', '');
			}
			
			
			// collapsable menu blocks
			$("ul.menu ul.collapsable-container").accordion({
				collapsible: true,
				header: "> li strong"
			});
			
			
			// hover fixes for IE 6
			if (LibMan.isMSIE && LibMan.vIE < 7) {
				$('nav ul li').hover(
					function(){ $(this).addClass('hover'); },
					function(){ $(this).removeClass('hover'); }
				);
			}			

			
			
			/*
			 * page-specific JS
			 */
			var $body = $("body");
			
				// home page JS
				if ($body.attr('id') == "home") {
					homeHero.init();
				}
				
				
				// product list page
				if ($body.hasClass('product-list')) {
					paginateProducts.init();
					
					// colour the product item borders on hover
					var $products = $('div.product-block a');
					$products.find('img').css({borderColor:"#e7e7e7"});
					$products.hover(
						function(){ $(this).find('img').stop().animate({borderColor:"#7a7a7a"}, 250); },
						function(){ $(this).find('img').stop().animate({borderColor:"#e7e7e7"}, 250); }
					);
				}
				
				
				// product page
				if ($body.hasClass('product')) {
					product.init();
				}
				
				
				// collections page JS
				if ($body.attr('id') == 'collections') {
					paginateCollections.init();
				}
				
				
				// collection pages JS
				if ($body.attr('id') == "collection") {
					collectionAccordion.init({
						animationTime : 250
					});
				}
				
		});


	/*
	 * Window load calls for all pages
	 */
		$(window).load(function() {
			
		});
