var $j = jQuery.noConflict();
   
// Use jQuery via $j(...)
$j(document).ready(function(){
	$j("#menu ul:first").addClass('sf-menu');
	$j("ul.sf-menu").supersubs({
		minWidth:    10,
		maxWidth:    27,
		extraWidth:  1
	}).superfish({
		dropShadows: false
	}).css({'visibility':'visible'});
	
	$j('body').supersleight({
		apply_positioning:false,
		shim:'/images/x.gif'
	});
	
	add_title_shadow();
	start_slideshow();
	clickifyProductCallouts();
});

function add_title_shadow() {
	if ($j('#explorer')) {
		$j('.slide').each(function() {
			h1 = $j(this).children('h1:first').clone()
			h1.css({'margin':'2px 0 0 2px', 'color':'#000', 'opacity':0.5});
			if ($j(this).children('h1:first').hasClass('white'))
				h1.css({'color':'#000'});
			if ($j(this).children('h1:first').hasClass('black'))
				h1.css({'color':'#fff'});
			$j(h1).prependTo($j(this));
		});
	}
}


var t;
function start_slideshow() {
	if ($j('#explorer')) {
		t = setInterval('automate_slide_switch()', 5000);
	}
}

var i_master = 1;
function switch_slide(item, stop) {
	if (stop) {
		clearInterval(t);
		i_master = 0;
	}
	$j('.slide').css({'z-index':'8'});
	$j('#slideshow-'+item).css({'z-index':'9', 'display':'block'});
	$j('#explorer ul li a').removeClass('active');
	$j('#explorer-'+item).addClass('active');
}

function automate_slide_switch() {
	if ($j('#explorer ul li a').eq(i_master).attr('id')!==undefined) {
		switch_slide($j('#explorer ul li a').eq(i_master).attr('id').replace(/explorer\-/gi, ''), false);
		i_master = i_master + 1;
		
		if (i_master==$j('#explorer ul li a').length) {
			i_master = 0;
		}
	}
}

function clickifyProductCallouts() {
	$j('.product-callout').each(function() {
		if ($j(this).find('a').length) {
			$j(this).click(function() {
				window.location = $j(this).find('a').first().attr('href');
			});
			$j(this).css({'cursor':'pointer'});
		}
	});
}
