var show_promo = null;
var cycle_news = null;
var new_song = null;

$(document).ready(function(){
	$('#show_time').jclock();

	// set up homepage news
	$("div.hn_news_container").show();
	$("#hn_selector_localnews").show();
	$("#nc_localnews").addClass("current");
	$("#hn_sub_news").addClass("current");
	hp_ShowHeadlines("localnews");
	
	ShowAnimatedPromobox();
	show_promo = setInterval("ShowAnimatedPromobox()", 9000);
	cycle_news = setInterval("hp_CycleNewsBox()", 7000);
	new_song = setInterval("RefreshSongFeed()", 60000);
	
//	$("div.carousel_gallery div.img_row a").fancybox({ 'overlayShow': true, 'overlayOpacity': 0.6 }); 
	$("div.gallerybox div.img_row a").fancybox({ 'overlayShow': true, 'overlayOpacity': 0.6 }); 
	$("#carousel-slider").show();
		
	$('.star-rating').each(function() 
	{ 
		$(this).rater({ postHref: '/inc/ajax/songrating.php' }); 
	}); 
	$('.nowplayingrate').rater({ postHref: '/inc/ajax/songrating.php' }); 
	
	FPWeather('forecast');
	
});

var hp_cycle_no = -1;

function RefreshSongFeed()
{
	$.get("/inc/ajax/songfeed.php", function(data){
  		$("#pnlSongfeed").html(data);
		
		$('.star-rating').each(function() 
		{ 
			$(this).rater({ postHref: '/inc/ajax/songrating.php' }); 
		}); 
	});
}

function hp_ShowNewsTab(id)
{
	var arrTabs = ['news', 'travel', 'weather', 'sport', 'showbiz'];
	
	for (var i=0; i<arrTabs.length; i++)
	{
		$("#hn_sub_" + arrTabs[i]).removeClass("current");
		$("div.hn_" + arrTabs[i] + "_container").hide();
	}
	
	$("#hn_sub_" + id).addClass("current");
	$("div.hn_" + id + "_container").show();	
}

function hp_CycleNewsBox()
{
	var arrTabs = ['news', 'travel', 'weather', 'sport', 'showbiz'];
	if (hp_cycle_no == (arrTabs.length - 1)) {hp_cycle_no = 0;}
	else {hp_cycle_no++;}
	hp_ShowNewsTab(arrTabs[hp_cycle_no]);
}

function hp_StopCycle()
{
	clearInterval(cycle_news);
}

function hp_ShowHeadlines(category)
{
	$(".hn_selector").hide();
	$("#hn_selector_" + category).show("slow");
	$("div.hn_news_categories ul li").removeClass("current");
	$("#nc_" + category).addClass("current");
}

function ViewVideo(video_id)
{
	$(document).bind('reveal.facebox', function() {
    	var so = new SWFObject("/inc/swf/jwplayer.swf", "irnplayer", "460", "288", "7", "#FFFFFF");
        so.addParam("allowfullscreen", "false");
		so.addParam("allowscriptaccess", "always");
		so.addParam("flashvars", "file=" + video_id + "&autostart=true");
        so.write("video_player");

	}); 
	jQuery.facebox('<div id="video_player"></div>');
}

function ViewMusicVideo(myFlashVars)
{
	$(document).bind('reveal.facebox', function() {
    	var so = new SWFObject("http://cdn.last.fm/videoplayer/l/17/VideoPlayer.swf", "lfmEmbed_50_35218125_1516938242", "450", "373", "7", "#FFFFFF");
 //       so.addParam("title", "Boys+And+Girls+-+Remix+Version");
	//	so.addParam("uniqueName", "35218125");
	//	so.addParam("albumArt", "http%3A%2F%2Fcdn.last.fm%2Fdepth%2Fcatalogue%2Fnoimage%2Fnocover_flashplayer.png");
	//	so.addParam("duration", "225");
	//	so.addParam("image", "http%3A%2F%2Fuserserve-ak.last.fm%2Fserve%2Fimage%3A320%2F35218125.jpg");
	//	so.addParam("autostart", true);
	//	so.addParam("FSSupport", true);
	//	so.addParam("track", true);
	//	so.addParam("creator", "Pixie+Lott");
		so.addParam("flashvars", myFlashVars)
		
		so.write("video_player");

	}); 
	jQuery.facebox('<div id="video_player"></div>');
}

function ShowYouTube(video_id)
{
	$(document).bind('reveal.facebox', function() {
    	var so = new SWFObject("http://www.youtube.com/v/" + video_id, "utube", "425", "324", "9", "#FFFFFF");
    	so.addParam("wmode", "transparent");
    	so.addVariable("autoplay", "1");
        so.write("utube_player");

	}); 
	jQuery.facebox('<div id="utube_player"></div>');
}

function ListenLive()
{
	window.open("/listenlive/","RadioPlayer",
				"status=0,toolbar=0,location=0,menubar=0,resizable=0,scrollbars=0,width=700,height=320");
}

function ShowAnimatedPromobox()
{
	$("span.promobox_animate").each(function (i) 
	{
		$(this).find('a').hide();
		var total = $(this).find('a').length;
		var rand = Math.floor(Math.random()*total);
		if( !$.browser.safari )
		{
			$(this).find('a').slice(rand,rand+1).fadeIn("slow");
		}
		else
		{
			$(this).find('a').slice(rand,rand+1).show();
		}
	});
}

function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function SendGtalkMessage()
{
	$("#gtalk_messagebox").show("slow");
}

function SendGtalkMessage2()
{
	var from = $("#txtGtalkFrom").val();
	var message = $("#txtGtalkMessage").val();
	
	if ((from.length > 2) && (message.length > 4))
	{
		jQuery.get("/inc/php/send-gtalk.php?from=" + from + "&message=" + message);
		$("#txtGtalkFrom").val(""); $("#txtGtalkMessage").val("");
		$("#gtalk_messagebox").hide();
		alert("Your message has been sent. Thank you!");
	}
	else
	{
		$("#txtGtalkFrom").val(""); $("#txtGtalkMessage").val("");
		$("#gtalk_messagebox").hide();
	}
}

function CloseGtalkMessage()
{
	$("#txtGtalkFrom").val(""); $("#txtGtalkMessage").val("");
	$("#gtalk_messagebox").hide();
}

function FPWeather(action)
{
	$("#fw_weathernow, #fw_forecast, #fw_hotspots").hide();
	if (action == "weathernow")
	{
		$("#fw_weathernow").show();
	}
	else if (action == "forecast")
	{
		$("#fw_forecast").show();
	}
	else if (action == "hotspots")
	{
		$("#fw_hotspots").show();
	}
}

function SendContactMessage()
{
	$("#contact_messagebox").show("slow");
}

function CloseContactMessage()
{
	$("#contact_messagebox").hide();
}


