/* Custom onload handler */
var dolFunctions = new Array(); // array to hold customized affiliate functions and params for "DOM load" functions
var wolFunctions = new Array(); // array to hold customized affiliate functions and params for "window load" functions

// search **********************************************************************
function searchFormSubmit(form) {
	if (form.searchSelect[1].checked == true) {
		// this address needs to be changed once search is set up
		window.location = "http://nl.newsbank.com/nl-search/we/Archives?p_multi=EN|&p_product=EN&p_theme=realcities2&p_action=search&p_maxdocs=200&s_site=miami&s_trackval=MH&p_text_search-0=" + form.sf_pubsys_story.value + "&s_dispstring=" + form.sf_pubsys_story.value + "%20AND%20date(all)&xcal_numdocs=20&p_perpage=10&p_sort=YMD_date:D&xcal_useweights=no";
		return false;
	} else if (form.searchSelect[2].checked == true) {
                window.location = "http://www.elnuevoherald.com/cgi-bin/mi/overture/overture.pl?Keywords=" + form.sf_pubsys_story.value;
                return false;
        }
	return true;
}
// end search ******************************************************************



function today_string() {
	// dependant on date functions defined in mi-utilities.js
	var today = new Date();
	return today.spanishDay()+', '+today.getDate()+' de ' + today.spanishMonth(true)+' del '+today.getFullYear();
}

// ppRichMedia *****************************************************************

function ppRichMedia(object, type) {
  // default flv playback
  var width = 783;
  var height = 430; 
  if (type == "mp3")
  {
    width = 322;
    height = 470;
  }
  var left = window.screen.width/2 - width/2;
  var top = window.screen.height/2 - height/2;
  window.open(object.href,'mh' + type ,'width=' + width + ',height=' + height + ',resizable=no,left=' + left + ',top=' + top + ',screenx=' + left + ',screeny=' + top);
  return false;
}

// setColWidth *****************************************************************

function setColWidth(leftRightWidth) {
	document.write("<style type=\"text/css\">\n");
	for ( var i = leftRightWidth.length - 1; i >= 0; i--)
	{
		if(i == (leftRightWidth.length - 1))
		{
			document.write("div.left_half { width: " + (leftRightWidth[i][0] - 0.1) + "%; }\n");
			document.write("div.right_half { width: " + (leftRightWidth[i][1] - 0.1) + "%; }\n");
		}
		else {
			document.write("div.Left_" + (i+1) + " { width: " + (leftRightWidth[i][0] - 0.1) + "%; }\n");
			document.write("div.Right_" + (i+1) + " { width: " + (leftRightWidth[i][1] - 0.1) + "%; }\n");
		}
		document.write("div.Left_" + (i+1) + "_Right div.lrc2 { background: url(http://media.elnuevoherald.com/images/gdot.gif) repeat-y 0" + leftRightWidth[i][0] + "%; }\n")
	}
	document.write("</style>\n");
}

// findPos *********************************************************************

function findPos(obj) { //returns the x & y coordinates of an element
        var curleft = obj.offsetLeft || 0;
        var curtop = obj.offsetTop || 0;
        while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
        }
        return {x:curleft,y:curtop};
}

// onloadFunctions *************************************************************

function onloadFunctions(myFunction,flag) {
        if(flag == "d")
        {
                dolFunctions[wolFunctions.length] = myFunction;
        }
        else
        {
                wolFunctions[wolFunctions.length] = myFunction;
        }
}

// initLoad ********************************************************************

function initLoad(){
        for(var i=0; i < wolFunctions.length; i++)
        {
                eval(wolFunctions[i]);
        }
}

// dummies *********************************************************************

function equalHeight() {}

function equalHeightLR() {}

function setLeftRightWidth() {}

function customInit() {}

// *****************************************************************************

$(function() { //Initialization function, runs when the DOM has loaded
        customInit(); // this will fire off any customized affiliate "load" functions
});

// *****************************************************************************

addEvent(window,'load',initLoad);


//experimental temporary fix for munged bylines 
$(document).ready(function(){
var mybyline = $(".byline").text();
if (mybyline == "")
$("#storyBody > p:contains('\/ AP')").addClass("byline").insertBefore(".credit_line");
$("#storyBody > p:contains('\/ AFP')").addClass("byline").insertBefore(".credit_line");
$("#storyBody > p:contains('\/ EFE')").addClass("byline").insertBefore(".credit_line");
$("#storyBody > p:contains('\/ The Miami Herald')").addClass("byline").insertBefore(".credit_line");
$("#storyBody > p:contains('\/ Bloomberg')").addClass("byline").insertBefore(".credit_line");
$("#storyBody > p:contains('\/ MCT')").addClass("byline").insertBefore(".credit_line");
$("#storyBody > p:contains('\/ McClatchy')").addClass("byline").insertBefore(".credit_line");
$(".byline").css("text-align","left");
  });

