function windowOpen(url) { 
    popUp(url,"terms",0,1,0,0,0,0,800,600); 
    return "opened"; 
}

function popUp(URL,name,toolbar,scrollbars,location,statusbar,menubar,resizable,width,height) { 
    eval(name + " = window.open(URL, '" + name + "', 'toolbar="+toolbar+",scrollbars="+scrollbars+",location="+location+",statusbar="+statusbar+",menubar="+menubar+",resizable="+resizable+",width="+width+",height="+height+"');"); 
}

function setupVideoPlayer() {
    // select default video in left nav
    var firstvid = $('#videoList li:eq(0) li:eq(1) a');
	$(firstvid).parent().addClass('selected');
	$('#esportVideoTitle').text($(firstvid).text());
	
	// set up left nav
	$('#videoList ul a').click(function(){
	    $('#esportVideo').hide();
	    $('#videoList li.selected').removeClass('selected');
	    $(this).parent().addClass('selected');
	    var file = $(this).attr('href');
	    var so1 = new SWFObject(file, "esportVideoPlayer", "400", "300", "6", "#ffffff");
	    so1.addParam("wmode", "transparent");
	    so1.write("esportVideo");
	    $('#esportVideo').show();
	    $('#esportVideoTitle').text($(this).text());
	    return false;
	});

	var idx = location.href.indexOf('?');
	var videoID = location.href.substring(idx+1);

	if (videoID != "") {
	    $(videoID).click();

	}
	
	
	
	// show sub nav
	$('#videoList ul').slideDown();
}

function setupBreadcrumbs() {
    $('.breadcrumbs span:last a').addClass('current');
}

function setupHomeFeatureRotate() {
    var interval = 6000; // in milliseconds
    var p = $('#homeFeature img').length - 1;
    var rotateInterval = setInterval(rotate, interval);
    
    $('#homeFeature img').css({opacity:0}).eq(p).css({opacity:1});
        
    function rotate() {
        $('#homeFeature img').eq(p).animate({opacity:0}, 500);
        if (p == ($('#homeFeature img').length - 1))
            $('#homeFeature img').eq(p=0).animate({opacity:1}, 500);
        else
            $('#homeFeature img').eq(++p).animate({opacity:1}, 500);
    }
}

$(document).ready(function() {
	$("a[rel='external']").attr("target","_blank");
    
    // table odd/even rows
    $('table').each(function(){
        $('tr:even', this).addClass('even');
        $('tr:odd', this).addClass('odd');
    });
    
    // sets suckerfish nav classes in IE
    if ($.browser.msie) {
        $('.navigation li').hover(function(){$(this).addClass('sfhover');},function(){$(this).removeClass();});
        if ($.browser.version == 6) {
			//$('.navProfile img, .navProfile input, #profileStart a img').each(function(){$(this).pngFix()});
		}
    }

	$('.footerLink li').not(':last').addClass('border');
	$('.footerLink li:first').prepend('<li>[</li>');
	$('.footerLink').append('<li style="padding:0">]</li>');
	
	// hide footer hr from home page
	$('#home').each(function() { $('#hr').hide(); });
	
	if(typeof sIFR == "function"){
	    sIFR.replaceElement("h2.fr", named({sFlashSrc: "/Common/Include/HelveticaNeueCondensed.swf", sColor: "#002288", sCase: "upper", sWmode: "transparent", sFlashVars:"letterSpacing=4"}));
	    sIFR.replaceElement("h3.fr", named({sFlashSrc: "/Common/Include/HelveticaNeueCondensed.swf", sColor: "#ff9933", sCase: "upper", sWmode: "transparent", sFlashVars:"letterSpacing=2"}));		
		// sIFR.replaceElement("h2.fr", named({sFlashSrc: "/Common/Include/HelveticaNeue.swf", sColor: "#003399", sCase: "upper", sWmode: "transparent"}));
		// sIFR.replaceElement("h3.fr", named({sFlashSrc: "/Common/Include/HelveticaNeue.swf", sColor: "#ff9933", sCase: "upper", sWmode: "transparent"}));
		// sIFR.replaceElement("h4.fr", named({sFlashSrc: "/Common/Include/HelveticaNeue.swf", sColor: "#e51937",  sWmode: "transparent"}));
		// sIFR.replaceElement("h5.fr", named({sFlashSrc: "/Common/Include/HelveticaNeue.swf", sColor: "#003399", sCase:"upper",  sWmode: "transparent"}));
		// sIFR.replaceElement("h6.fr", named({sFlashSrc: "/Common/Include/HelveticaNeue.swf", sColor: "#e51937", sLinkColor: "#e51937", sHoverColor: "#ffac59", sCase:"upper",  sWmode: "transparent" }));
	};
});

$(window).load(function(){
	$('.rollover').hover(function(){$(this).attr('src', $(this).attr('src').split('_off').join('_on'))}, function(){$(this).attr('src', $(this).attr('src').split('_on').join('_off'))});
	$('.navigation ul a').hover(
		function() {
			var u = $('.navigation ul').index($(this).parent().parent()[0]);
			var j = $('a', $('.navigation ul:eq('+u+')')).index($(this)[0])*-22;
			switch(u)
			{
				case 1:
				$(this).css({background: "url(/Common/Images/navTreatment.gif) 0 "+j+"px no-repeat"});
				break;
				
				case 2:
				$(this).css({background: "url(/Common/Images/navProfessionals.gif) 0 "+j+"px no-repeat"});
				break;
				
				default:
				$(this).css({background: "url(/Common/Images/navProducts.gif) 0 "+j+"px no-repeat"});
				break;
			}
		},
		function() {$(this).css({background: 'none'});}
	);
	
	$('.assistantmap area').hover(function(){
	    $('#iassistant')[0].section = $(this).attr('title');
	    $('#iassistant').attr({src: ($.browser.msie && ($.browser.version == 6))?'/Common/Images/assistant'+$('#iassistant')[0].section+'.gif':'/Common/Images/assistant'+$('#iassistant')[0].section+'.png'})
	},function(){
	    $('#iassistant').attr({src: '/Common/Images/superpixel.gif'})
	});
	
	$('#AssistantMapInternal area').click(function(){
	    $('#AssistantSection .section').hide();
	    $($(this).attr('href')).show();
	    return false;
	});
	
	$('.submenu a').click(function(){
	    $('#AssistantSection .subsection').hide();
	    $($(this).attr('href')).show();
	    return false;
	});
	
	setupVideoPlayer();
	
	setupBreadcrumbs();
	
	setupHomeFeatureRotate();
	
	$('#printPage').click(function(){
	    window.print();return false;
	});
	
	$('#homeFoot .infoBox, #panelTapingVideos, #panelNewsletterSignup').hover(function(){
	    $('a', this).css({color:'#ff9933'});
	},function(){
	    $('a', this).css({color:'#e51937'});
	}).click(function(){
		if ($('a', this).attr('target') == '_blank') {
			window.open($('a', this).attr('href'));
			return false;
		}
        else {
        	location.href = $('a', this).attr('href');
        	return false; //applies the anchor url to the entire panel, returns false so that two instances aren't triggered if the user clicks the anchor
    	}
    });
    
    $('#btnBack').click(function(){
        $(this).attr('href', $('.breadcrumbs span a[href*="/Products/Default.aspx"]').attr('href'));
    });


    /** **/
    $('#rightColProductDetail .infoBoxProductDetail').hover(function() {
        $('a', this).css({ color: '#ff9933' });
    }, function() {
        $('a', this).css({ color: '#e51937' });
    }).click(function() {
        location.href = $('a', this).attr('href'); return false; //applies the anchor url to the entire panel, returns false so that two instances aren't triggered if the user clicks the anchor
    });
   
});

$(document).ready(function() {
    var randomImages = ['image_01', 'image_02', 'image_03', 'image_04'];
    var rndNum = Math.floor(Math.random() * randomImages.length);
    $("div.wrap").css({ background: "url(/Common/Images/imagesLHS/bg" + randomImages[rndNum] + ".jpg) center center no-repeat" });
});
