documentReadyListeners = new Array();

/**
 * Keeps an array of all registered document ready listeners. This
 * are invoked when the page is loaded by full page load or AJAX
 */
function documentReady(fnName){
	documentReadyListeners.push(fnName);
}

/**
 * Invokes all registered document ready listeners
 */
function invokeDocumentReadyListeners(firesifr){
	for(i=0; i<documentReadyListeners.length; i++)
	{
		eval(documentReadyListeners[i] + "()");
	}	
}

/**
 * Define the global document ready handler
 */
jQuery(document).ready(function(){
    invokeDocumentReadyListeners(false);
});

function splitValue(value, token, index){
    var arr = value.split(token);
    return arr[index];
}

String.prototype.stripSpaces = function( ){ return this.replace( /\s/g, "" ); };

function whiteSpace(value){
    value = value.replace(/^\s*|\s*$/g, '');
    return value;
}

function removeSpaces(string) {
 return string.split(' ').join('');
}

function getParam(name){
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var result = regex.exec(window.location.href);
    if (result == null) 
        return "";
    else 
        return result[1];
}

function splitValue(value, token, index)
{
	 var arr = value.split(token);
 	 return arr[index];
} 

function vj_popup(url, width, height)
{
	 var params = 'width='+ width;
	 params += ', height='+ height;
	 params += ',menubar=yes';
	 params += ',toolbar=yes';
	 params += ',resizable=yes';
	 window.open(url,"", params);
}

function addCarousel(id, movieLocation, width, height, alt)
{
	var flashvars = {};
	var params = { };
	var attributes = {};
	
	flashvars.xmlpath = escape(jQuery("[id$='"+id+"']").attr("class"));
	flashvars.holdfor = "5";
	params.wmode = "opaque";
	
	var myMovie = movieLocation;
	var expressInstall = "/javascript/swfobject/expressInstall.swf";
	
	swfobject.embedSWF(myMovie, alt, width, height, "9.0.0", expressInstall, flashvars, params, attributes);
}

documentReady("attachPopupCode");
function attachPopupCode()
{
	jQuery(".shareLink").click( function() {
		vj_popup(jQuery(this).attr("href"), 0, 0);
		return false;
	});
}

documentReady("checkForCataloguePane");
function checkForCataloguePane() {
    var catalogueResultsPane = jQuery(".catalogueResultsPane");
    if (catalogueResultsPane.length > 0) {
        sortHeights();
    }
}

function sortHeights() {
    // Make each div as tall as the tallest div
    // Ensure that all the 
    var maxHeight = 0;
    var maxImgHeight = 0;
    var mediaItemInfo = jQuery(".mediaItemInfo");

    mediaItemInfo.each(function() {
        if (jQuery(this).height() > maxHeight) { maxHeight = jQuery(this).height(); }
        if (jQuery(this).height() > maxImgHeight) { maxImgHeight = jQuery(this).find("img").height(); }
        if (jQuery(this).find("img").length == 0 && jQuery(this).find("h3").length > 0) {
            jQuery(this).find("h3").addClass("noImage");
        }
    }).height(maxHeight);

    jQuery("h3.noImage").css("padding-top", maxImgHeight + 30 + "px").css("margin-top", "0")

    jQuery(".mediaItemRow:last").addClass("last");
}
