// set up mega dropdown rollover
/*
$(function() { 
	$('.menu-582 a').mouseenter( function() { 
		$('#mega').show().mouseleave( function() {
			$('#mega').fadeOut('fast').unbind();
		});
	})
});
*/

if (!$) $ = jQuery;

var urlParams = {};
function parseUrlParams() {
    var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&=]+)=?([^&]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);

    while (e = r.exec(q))
       urlParams[d(e[1])] = d(e[2]);
}

var hideMegaTO = null;
function hideMega() {
	$('#mega_header').fadeOut('fast').unbind();
	$('#mega').fadeOut('fast').unbind();
	hideMegaTO = null;
}

var currentFeature = 1;
var featureInterval = null;

function resetFeatureInterval() {
	clearInterval(featureInterval);
	featureInterval = setInterval('nextFeature();', 20000);
}

function goToFeature(newFeature) {
	if (currentFeature == newFeature) return;
	
	$('#feature_number_links li:nth-child(' + currentFeature + ')').removeClass('active');
	$('#feature_number_links li:nth-child(' + newFeature + ')').addClass('active');

	$('#home_feature_image_' + newFeature).css('z-index', 2).fadeIn();
	$('#home_feature_image_' + currentFeature).css('z-index', 1).fadeOut();
	
	$('#home_feature_' + newFeature).fadeIn();
	$('#home_feature_' + currentFeature).fadeOut();
	
	currentFeature = newFeature;
}

function nextFeature() {
	var cur = $('#feature_number_links li.active');
	if (cur.length == 0) {
		clearInterval(featureInterval);
		return;
	}
	
	var next = (cur.next().length == 0) ? cur.siblings().first() : cur.next();
	var id = next.attr('id');
	goToFeature(eval(id[id.length - 1]));
}

function pauseFeatures() {
	clearInterval(featureInterval);
	featureInterval = null;
}

$(function() { 
	$('#menu-item-329 a').mouseenter( function() { 
		$('#mega_header').show();
		$('#mega').show();
		
		$('#mega,#mega_header').mouseleave( function() {
			hideMegaTO = setTimeout('hideMega()', 50);
		}).mouseenter( function() {
			clearTimeout(hideMegaTO);
		});
	});
	
	$('#feature_number_links li').each(function (index, obj) {
		$(obj).click(function () { 
			goToFeature(index + 1);
			resetFeatureInterval();
		});
	});
	
	$('input.ghost').each(function() {
		$(this).blur(function() {
			if (($(this).val() == '') || ($(this).val() == $(this).attr('title'))) {
				$(this).val($(this).attr('title')).css({'color': '#999'});
			}
		}).focus(function() {
			if ($(this).val() == $(this).attr('title')) {
				$(this).val('').css({'color': '#000'});
			}
		});
		
		$(this).blur();
	});

	$('.order-review-table tr td.data-col:contains("PayPal")').html('PayPal or major credit card');	
	
	if ($(document).prettyPhoto != null)
		$("a[rel^='prettyPhoto']").prettyPhoto({
			theme: 'light_rounded',
			allow_resize: false,
			show_title: false,
			callback: function() { resetFeatureInterval(); }
		}).click(pauseFeatures);
		
	resetFeatureInterval();
});

