/*
	site_utils

	Created by John Hunter 2007-11-27.
	Licence CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
	Modified: 2008-01-12
*/


// for debugging:
if (typeof console == 'undefined') console = {info: function(){}, log: function(){}};
//var mediaplayer = {loadAndPlay: function (title, data) { console.info("mediaplayer.loadAndPlay('"+ title + "', '" + data + "')"); }}; // TEMP TESTING - remove this line
// end debugging



$(document).ready(function () {
	makeMPplayLinks ();
	
	subscribe2widget.init();
    
    $(".thumbImage").corner("10px");
});


function makeMPplayLinks () {
	$('ul.mp-command-container li a.more').each(function () {
		var that = $(this);
		var title = that.attr('title');
		var li = that.parent();
		li.before('<li><a class="mp-play" href="#media-player" title="'+ title +'">watch video</a></li>');
		li.prev().children().click(function () {
			window.callMPplay(title);
		});
	});
}


// for Flash's ExternalInterface
function thisMovie(movieName) {
	 if (navigator.appName.indexOf("Microsoft") != -1) {
	     return window[movieName];
	 } else {
	     return document[movieName];
	 }
}
function isReady() {
	return true;
}
function loadAndPlay(contentTitle, data) {
	 thisMovie("mediaplayer").loadAndPlay(contentTitle, data);
}

 
function callMPplay (contentTitle) {
	// call the movie play method passing the title and the json settings data
	var data = childrenMPSettings[contentTitle] || '[]';
	if (data) {
		loadAndPlay(contentTitle, data);
	}
}


var subscribe2widget = {
	control: null,
	controlLink: null,
	panel: null,
	isOpen: false,
	
	init: function () {
		this.control = $('#subscribe2widget h2');
		this.panel = $('#subscribe2widget div.search');
		this.hide(null, 'fast');
		this.controlLink = this.control.wrapInner('<a href="#" id="subscribe2widget-control"></a>');
		$('#subscribe2widget-control').click(function () { subscribe2widget.show(); return false; });
	},
	show: function () {
		this.controlLink.blur();
		if (this.isOpen) return this.hide();
		this.isOpen = true;
		this.panel.slideDown('slow');		
		return this;
	},
	hide: function (e, speed) {
		var speed = speed || 'slow';
		this.isOpen = false;
		this.panel.slideUp(speed);
		return this;
	}
};
