/* htdocs/fergweb/js/main.js
   $Id: main.js,v 1.4 2012-02-03 18:53:33 dferruggia Exp $ */

/* Global (site wide) javascript functions */

// return true if capable of displaying SWF files.
function isSWFcapable () {
	if (navigator.userAgent.match(/iPhone/i) || 
	    navigator.userAgent.match(/iPod/i) ||
	    navigator.userAgent.match(/iPad/i)
	) { return false ; }
	return true;
}
	
// getPageSize
function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {    // all except Explorer
		if (document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth) {
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize;
}

// getPageScroll
function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {     // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	arrayPageScroll = new Array(xScroll, yScroll);
	return arrayPageScroll;
}

// Gets the value of a parameter, ie: var email = getParameterByName('email');
function getParameterByName(name) {
	var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
	return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

// Global jQuery setup
jQuery().ready(function() {
	
	// Make the "buttons" change in the header.
	$("#email_signup_button a span, #location_finder_button a span, #fol_login_button a span, #shop_online_button a span").css('opacity', 0);
	$("#email_signup_button a span, #location_finder_button a span, #fol_login_button a span, #shop_online_button a span").hover(
		function () {$(this).stop().animate({opacity: 1}, 500) },
		function () {$(this).stop().animate({opacity: 0}, 500) }
	);

	// helper class definitions for tipTip.
	$(function(){ $(".tipAny").tipTip({attribute: 'data-tip'}) });
	$(function(){ $(".tipTop").tipTip({attribute: 'data-tip', defaultPosition: 'top'}) });
	$(function(){ $(".tipBottom ").tipTip({attribute: 'data-tip', defaultPosition: 'bottom'}) });
	$(function(){ $(".tipLeft").tipTip({attribute: 'data-tip', defaultPosition: 'left'}) });
	$(function(){ $(".tipRight").tipTip({attribute: 'data-tip', defaultPosition: 'right'}) });

	// enable any ui accordions
	$(function() {
		$( ".accordion" ).accordion({
			active: '.accordion-selected',
			animated: 'easeOutExpo',
			autoHeight: false,
			fillSpace: false,
			header: '.accordion-header'
		});
	});

	// enable video links
	if (isSWFcapable()) {
		$('#videoLink').show();
		$('a span.dataSource').parent().click(function() {
			runSWFPlayer($(this).find('span.dataSource').html());
			return false;
		});
	} 

	// read more... sections
	jQuery( ".readMore" ).accordion({
		animated: 'easeOutExpo',
		autoHeight: false,
			fillSpace: false,
			collapsible: true,
			active: false,
			header: '.readMoreHeader'
	});
	
	// for the time being, this closes ALL accordions of the "readMore" class.
	jQuery( ".readLessFooter" ).live('click', function(e) {
		e.preventDefault();
		jQuery( ".readMore" ).accordion("option", "active", false);
	});

});


