var MEDIAPLAYER = "/js/shadowbox/libraries/mediaplayer/player-licensed.swf";
var EXPRESSINSTALL = "/js/shadowbox/libraries/swfobject/expressInstall.swf";

var uri = parseUri(document.location.href);

//google.load("jquery", "1.3");
//google.load("jqueryui", "1.7");
var google = {setOnLoadCallback:$};

Shadowbox.init({
	players: ['img','flv','swf']
});

var LOG_ON = false;
function LOG(message) {
	if (!LOG_ON) return;
	if (!('console' in window)) {
		console = {};
	}
	if (!('log' in console)) {
		console.log = alert;
	}
	console.log(message);
}

var player;
var playerLoadIndex;
function playerLoadItem() {
	player.sendEvent('ITEM',playerLoadIndex);
}
function playerPlaylistLoaded(obj) {
	var playlist = player.getPlaylist();
	if (uri.queryKey.file) {
		for (var i=0; i<playlist.length; i++) {
			if (playlist[i].file==uri.queryKey.file) {
				playerLoadIndex = i;
				// NOTE: selected video won't highlight in playlist on mac without delay?
				// NOTE: stupid IE6 won't do setTimeout at all?
				playerLoadItem(); //setTimeout(playerLoadItem,1000);
				break;
			}
		}
	}
}
function checkPlayerPlaylistLoaded() {
	LOG('checkPlayerPlaylistLoaded:');
	// if the playlist is already loaded, the listener will never trigger
	if (player.getPlaylist().length) {
		playerPlaylistLoaded(null);
	} else {
		player.addControllerListener('PLAYLIST','playerPlaylistLoaded');
	}
}
function playerReady(obj) {
	// NOTE: not being called on www2.fabrand.com on non-cached page
	LOG('playerReady:');
	if (obj.id=='videoPlayer-video') {
		player = $('#'+obj.id).get(0);
		checkPlayerPlaylistLoaded();
	}
}

$(function(){
	
	$('a.expanding').next('ul').each(function(){
		var me = $(this);
		var parent = me.prev('a');
		var active_li = me.find('li.active');
		if (active_li.length) {
			parent.addClass('open');
		} else {
			parent.addClass('closed');
			me.hide();
		}
	});
	$('a.expanding').click(function(eventObject){
		var me = $(this);
		var ul = me.next('ul');
		if (ul.length) {
			if (ul.is(':visible')) {
				ul.slideUp('fast');
				me.removeClass('open');
				me.addClass('closed');
			} else {
				ul.slideDown('fast');
				me.removeClass('closed');
				me.addClass('open');
			}
			return false;
		}
	});

    /* Decoy Spread Tabs */
    $('.box .box-bttm:first').siblings('.box-bttm').hide();
    $('.box .nav-tab li a').click(function(eventObject){
        var me = $(this);
        var li = me.parent();
        var box = $(me.attr('href'));
        li.addClass('active').siblings('li.active').removeClass('active');
        box.show().siblings('.box-bttm:visible').hide();
        return false;
    });
    
    /* Footer Quick Links */
    $('.footer li.links ul.quick-links').hide().css('height','0px');
    $('.footer li.links').mouseenter(function(eventObject){
        var me = $(this);
        me.find('.quick-links').animate({height:'150px',top:'-150px'},{queue:false,duration:'fast'});
    });
    $('.footer li.links').mouseleave(function(eventObject){
        var me = $(this);
        me.find('.quick-links').animate({height:'0px',top:'0px'},'fast','',function(){$(this).hide();});
    });

   
	// jcarousel
	//$.getScript('/js/jcarousel/lib/jquery.jcarousel.pack.js',function(){
		$('#videoCarousel2 .videoThumb').css('display','block');
		$('#videoCarousel2').jcarousel({
			vertical:true,
			visible:7
		});
	//});

});

