sfHover = function() {
	if (document.getElementById("navbar")) {
		var sfEls = document.getElementById("navbar").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			};
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			};
		}
	}
};
if (window.attachEvent){
	window.attachEvent("onload", sfHover);
}

function imgChange1( img ) { document.lamp1.src = img; }
function imgChange2( img ) { document.lamp2.src = img; }
function imgChange3( img ) { document.lamp3.src = img; }
function imgChange4( img ) { document.lamp4.src = img; }
function imgChange5( img ) { document.lamp5.src = img; }
function imgChange6( img ) { document.lamp6.src = img; }
function imgChange7( img ) { document.lamp7.src = img; }

// add to playlist
function add_to_playlist (key) {
	$.ajax({
		type: "POST",
		url: "/playlist/add_to_playlist",
		dataType: "script",
		data: "episode_key="+key
	});
}

function share_clip(user_email, email, message, user_name, media_key, start_time, end_time){
	$.post( '/video/share_clip', {'from_email' : user_email, 'email': email, 'message': message, 'media_key': media_key, 'start_time' : start_time, 'end_time' : end_time, 'user_name' : user_name}, null, "xml");
}

function play_wblender_mix (id) {
		var flashvars = {
			videoURL: "/remixes/"+id+"/remix.xml",
			host: "rtmpe://wbworldtv.fcod.llnwd.net/a2246/o23/",
			autoPlay: 1,
			fmsVersion: 3
		};

		var params = {
			menu: "false",
			wmode: "transparent",
			allowscriptaccess: "true"
		};

		var attributes = { };

		swfobject.embedSWF("/swfs/wblender/WBPlayer-Release.swf", "wblender", "400", "325", "9.0.124" ,"/expressInstall.swf", flashvars, params, attributes);
		$('#wblenderbuttons').hide();
		$('#wblenderAfter').show();
		$('#wblenderAfterbuttons').show();
}

// popup box code
function OpenUserWin(command){
	var newwin = window.open("/pages/"+command,'open','width=650,height=664,status=yes,scrollbars=yes,resizable=no,location=no,toolbar=no');
	if (newwin){
		newwin.focus();
	} 
}

function SetActiveTab( account )
{
	if ( account < 1 ) account = 1;
	if ( account > 4 ) account = 4;

	g_activeaccount = account;

	$('#account1').attr('class','account1inactive');
	$('#account2').attr('class','account2inactive');
	$('#account3').attr('class','account3inactive');

	//$('.tab'+tab+'style').addClass('tab'+tab+'hover');
	$('#account'+account).addClass('account'+account+'active');
	
	if ( account == 1 )
	{
		$('#accountpad1').attr('class','padpostactive');
		$('#accountpad2').attr('class','padinactive');
		$('#accountpad3').attr('class','padinactive');
	}
	else if ( account == 2 )
	{
		$('#accountpad1').attr('class','padpreactive');
		$('#accountpad2').attr('class','padpostactive');
		$('#accountpad3').attr('class','padinactive');
	}
	else if ( account == 3 )
	{
		$('#accountpad1').attr('class','padinactive');
		$('#accountpad2').attr('class','padpreactive');
		$('#accountpad3').attr('class','padpreactive');
	}
}

$(document).ready(function() {
	if ($('#mycarousel').length>0) {$('#mycarousel').jcarousel();};
	if ($('#mycarousel2').length>0) {$('#mycarousel2').jcarousel();};
	if ($('#mycarousel3').length>0) {$('#mycarousel3').jcarousel();};
	
	// preload images
	var img = ['account-active.gif','account-inactive-hover.gif','account-inactive.gif',
		'playlist-active.gif','playlist-inactive-hover.gif','playlist-inactive.gif',
		'pad-inactive.gif','pad-post-active.gif','pad-pre-active.gif',
		'remixes-active.gif','remixes-inactive-hover.gif','remixes-inactive.gif'];

	$(img).each(function () {
		var i = new Image();
		i.src = '/images/' + this;
	});

	$("#account1").bind("click", function(e){
		window.location = "/account/";
		return false;
	});

	$("#account2").bind("click", function(e){
		window.location = "/playlists/";
		return false;
	});

	$("#account3").bind("click", function(e){
		window.location = "/remix/";
		return false;
	});

	$('#account1').hover(function() {
			$(this).addClass('account1hover');
		}, function() {
		if ( g_activeaccount != 1 )
			$(this).removeClass('account1hover');
	});

	$('#account2').hover(function() {
		$(this).addClass('account2hover');
		}, function() {
		if ( g_activeaccount != 2 )
			$(this).removeClass('account2hover');
	});

	$('#account3').hover(function() {
		$(this).addClass('account3hover');
		}, function() {
		if ( g_activeaccount != 3 )
			$(this).removeClass('account3hover');
	});

	SetActiveTab( 1 );
	init_login_area();
	hightlight_current();
});

function send_register_click(){
	s.pageName="New Registration Page";
	s.channel="Registration";
	s.prop1="The WB.us";
	s.prop2="";
	s.prop3="";
	s.prop4="";
	s.prop5="";
	s.prop6="";
	s.prop7="";
	s.prop8="";
	s.events="";
	s.eVar1="";
	s.eVar2="";
	s.eVar3="";
	s.eVar4="";
	s.eVar5="";
	s.t();
}

function init_login_area () {
	$.get('/account/login_area', function(data){
		$('#log_in_area').html(data);
	});
}

function el(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	} else if (window[id]) {
		return window[id];
	}
	return null;
}

function hightlight_current () {
	var current_path = window.location.pathname;
	var nav_image = $('#nav a[href='+current_path+'] img:first');

	if(nav_image.length == 1){
		var nav_image_src = nav_image.attr('src');
		var new_nav_image_src = nav_image_src.replace('.gif', '-on.gif');
		nav_image.attr({onmouseover: '', onmouseout: '', src: new_nav_image_src});
		if($('#nav a[href='+current_path+']').parent().parents('ul[onmouseout]:first').length == 1){
			var sub_nav_ul = $('#nav a[href='+current_path+']').parent().parents('ul[onmouseout]:first');
			sub_nav_ul.attr({onmouseover: '', onmouseout: ''});
		}
	} else {
		var sub_nav_image = $('#nav a[href='+current_path+']').parent().parent().parent().children('a').children('img:first');
		if(sub_nav_image.length ==1){
			var sub_nav_ul = $('#nav a[href='+current_path+']').parent().parents('ul[onmouseout]:first');
			var nav_image_src = sub_nav_image.attr('src');
			var new_nav_image_src = nav_image_src.replace('.gif', '-on.gif');
			sub_nav_image.attr({onmouseover: '', onmouseout: '', src: new_nav_image_src});
			sub_nav_ul.attr({onmouseover: '', onmouseout: ''});
		}
	}
}

function show_slide (slide_number) {
	current_slide = slide_number;
	$('.new_slides').hide();
	$('#new_slide_'+slide_number).show();
	set_slide_nav();
}

function set_slide_nav () {
	$('#new_slide_prev').hide();
	$('#new_slide_next').hide();
	if(current_slide != 1){
		$('#new_slide_prev').show();
	}
	if(current_slide != total_slides){
		$('#new_slide_next').show();
	}
}

//a fix for IE non-implementation of this...
if (!Array.prototype.indexOf){
  Array.prototype.indexOf = function(elt /*, from*/){
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++){
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

// *******************************************************************************
// SIFR CONFIG
// *******************************************************************************
var futura = {
      src: '/swfs/futura-new.swf'
};
 
sIFR.activate(futura);
 
// global page header
sIFR.replace(futura, {
	selector: 'div.pageheader',
	css: [
		'.sIFR-root { font-size: 30px; color: #f1369d; }'
	],
	wmode: 'transparent'
});

// global page header
sIFR.replace(futura, {
	selector: 'h3.pageheader',
	css: [
		'.sIFR-root { font-size: 20px; color: #f1369d; }'
	],
	wmode: 'transparent'
});

// blog posting title
sIFR.replace(futura, {
	selector: 'h2.postingtitle'
	,css: [
		'.sIFR-root { margin: 0; padding: 0; font-size: 22px; font-weight: normal; color: #000000; }'
		,'a { color: #000000; text-decoration: none; }'
		,'a:link { color: #000000; }'
		,'a:hover { color: #000000; text-decoration: underline; }'
	]
	,wmode: 'transparent'
});

// photos promo tout title
sIFR.replace(futura, {
	selector: 'div.photosheader',
	css: [
		'.sIFR-root { font-size: 16px; color: #fb6502; }'
      		,'a { text-decoration: none; font-weight: bold; }'
		,'a:link { color: #fb6502; }'
		,'a:hover { color: #fb6502; text-decoration: underline; }'
	],
	wmode: 'transparent'
});

// downloads promo tout title
sIFR.replace(futura, {
	selector: 'div.downloadsheader',
	css: [
		'.sIFR-root { font-size: 16px; color: #fb6502; }'
      		,'a { text-decoration: none; font-weight: bold; }'
		,'a:link { color: #fb6502; }'
		,'a:hover { color: #fb6502; text-decoration: underline; }'
	],
	wmode: 'transparent'
});

// photos promo tout title
sIFR.replace(futura, {
	selector: 'h3.photosh3',
	css: [
		'.sIFR-root { font-size: 22px; color: #f1369d; }'
	],
	wmode: 'transparent'
});

// downloads promo tout title
sIFR.replace(futura, {
	selector: 'h3.downloadsh3',
	css: [
		'.sIFR-root { font-size: 22px; color: #f1369d; }'
	],
	wmode: 'transparent'
});

// shows 'full episodes' title
sIFR.replace(futura, {
	selector: 'h3.fullepisodes',
	css: [
		'.sIFR-root { font-size: 18px; color:#e5389c; }'
	],
	wmode: 'transparent'
});

// shows 'full episodes' title
sIFR.replace(futura, {
	selector: 'h3.downloadsheading',
	css: [
		'.sIFR-root { font-size: 22px; color: #f1369d; }'
	],
	wmode: 'transparent'
});

// shows 'full episodes' title
sIFR.replace(futura, {
	selector: 'div.showheader',
	css: [
		'.sIFR-root { font-size: 20px; color: #f1369d; margin: 0; padding: 0; }'
	],
	wmode: 'transparent'
});

// shows headings
sIFR.replace(futura, {
	selector: 'h3.moduletitle',
	css: [
		'.sIFR-root { font-size: 18px; color: #e5389c; }'
	],
	wmode: 'transparent'
});

// account headings
sIFR.replace(futura, {
	selector: 'h3.accountheader',
	css: [
		'.sIFR-root { font-size: 16px; color: #f1359d; }'
	],
	wmode: 'transparent'
});

// blog post title
sIFR.replace(futura, {
	selector: 'div.posttitle',
	css: [
		'.sIFR-root { font-size: 22px; color: #000; }'
      		,'a { color: #000; text-decoration: none; }'
		,'a:link { color: #000; }'
		,'a:hover { color: #000; text-decoration: underline; }'
	],
	wmode: 'transparent'
});