// JavaScript Document

function pageWide()
{
    $("#middleDiv").css("width", "760px");
    $("#promoDiv").css("display", "none");
    $("#mainTextArea").css("width", "735px");
}


if (window.name != "pod") 
{
    window.name = "main";
}

function makeStateSelectOptions(target)
{
    var tmpStateList;
    var tmpReturnString;
    var tmpStateArray;
    var i;
    var selectFlag;

    var tmpStateList = "AL|AK|AZ|AR|CA|CO|CT|DC|DE|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY"
    tmpReturnString = tmpReturnString + "<option value=''>&#160;</option>"
    tmpStateArray = tmpStateList.split("|");
    tmpReturnString = '<select id="' + target + '_state" name="' + target + '_state">'

    for (i = 0; i < tmpStateArray.length; i++)
    {
        tmpReturnString = tmpReturnString + "<option value='" + tmpStateArray[i] + "'>" + tmpStateArray[i] + "</option>"
    }
    tmpReturnString = tmpReturnString + "</select>"
    document.getElementById(target).innerHTML = tmpReturnString;
}


function tmpPopup(url) 
{
    window.open(url, null, "height=600,width=800,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}



function setConsoleInfo(pageid) 
{
    //alert("called");
    //window.parent.document.getElementById("hdncurrentlocation").value = "";
    window.parent.currentLocation = "";
	
	
	window.parent.document.getElementById("curidspan").innerHTML = pageid;
	//window.parent.document.getElementById("currpageid").value = pageid;
	window.parent.currpageid = pageid;

}

function doRo(item) {
    $(item).animate({ opacity: 0.5 }, 150)
    $(item).animate({ opacity: 1.0 }, 150)

}

//TODO: this exist in functions and in main console functions
var tmpLastElement = "";
function makeActive(tmpElement) {

    //window.parent.document.getElementById("hdncurrentlocation").value = tmpElement;
    window.parent.currentLocation = tmpElement;
  
    
    tmpLocationArray = tmpElement.split("_")
    tmpElementID = tmpLocationArray[2];
    tmpStoryID = tmpLocationArray[1];

    //if (window.parent.document.getElementById("editmode").value == "true") {
    if (window.parent.editMode == true)
    {

        if (tmpLastElement != "") {
            //alert(tmpLastElement)
            document.getElementById(tmpLastElement).style.backgroundColor = "";
        }
        tmpLastElement = tmpElement;
        document.getElementById(tmpElement).style.backgroundColor = "#ffcc00";
       // window.parent.document.getElementById("hdncurrstoryid").value = tmpStoryID;
        window.parent.currStoryId = tmpStoryID;


       // window.parent.document.getElementById("activeIndicator").value = tmpElementID;
        window.parent.activeIndicator = tmpElementID;
        
    }
}


function loadPage(pageID)
{
    $.ajax({
    url: "/retrieval/getPageMainStory.aspx?pageid=" + pageID,
        cache: false,
        success: function(html)
        {
            $("#studio67contenteDiv").html(html + "This is page" + pageID);
        }
    });


}


function openBlog(item)
{
    itemToOpen = "blogOpen" + item;
    itemToClose = "blogEntry" + item;

    for (i = 0; i < 5; i++)
    {
        document.getElementById("blogOpen" + i).style.display = "none";
        document.getElementById("blogEntry" + i).style.display = "block";
    }

    // alert(item);
    document.getElementById(itemToClose).style.display = "none";
    document.getElementById(itemToOpen).style.display = "block";
}


function openRssFeed()
{
    window.location = "/story.aspx?storyid=26";
}


function toggleDiv(div)
{
    $("#"+div).toggle("fast");
}




//Moved to core.js
function swapFrame(url,tmpCurrTemplateID)
{
	window.location = url;
}


var prevItem;
function swapRotatorText(i) 
{
    
    $(prevItem).fadeOut("slow");
    $("#rotator" + i).fadeIn("slow");
    
    prevItem = "#rotator" + i;
}



var prevPodItem = "#pod1";
function swapPod(i) {
    var item = "#pod" + i;
    $(prevPodItem).fadeOut("slow");
    $(item).fadeIn("slow");

    prevPodItem = item;
}



var prevHomeItem = 0;
function swapHomeContent(id) {

    $(prevHomeItem).fadeOut("slow");
    $("#page" + id).fadeIn("slow");

    prevHomeItem = "#page" + id;
}


function swapHomeDiv(id) {
    var obj = "page" + id;

    document.getElementById("homeMain").style.display = "block";

    if (prevHomeItem != "#page" + id) {
        document.getElementById("page0").style.display = "none";
        document.getElementById("page1").style.display = "none";
        document.getElementById("page2").style.display = "none";

        swapHomeContent(id);
    }

}

function hideHomeContent() {

    if (prevHomeItem != 0) {
        var item = prevHomeItem.replace("#", "");
        document.getElementById(item).style.display = "none";
        document.getElementById("homeMain").style.display = "none";
        //document.getElementById("page1").style.display = "none";
        //document.getElementById("page2").style.display = "none";
        prevHomeItem = 0;
    }
}


function openEvite(id)
{
    var ScreenWidth=window.screen.width;
    var ScreenHeight=window.screen.height;	
    var movefromedge=0;
    placementx=(ScreenWidth/2)-((650)/2);
    placementy=(ScreenHeight/2)-((500+50)/2);
    var PopUpUrl= "evite.aspx?storyid=" + id

	window.open(PopUpUrl,"","width=350,height=550,toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0,left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
}

function sendPageLink(headline)
{
	tmpURL = "includes/sendPageLink.asp?pageID=" + document.getElementById("currentpageid").value;
	window.open(tmpURL, null, "height=600,width=800,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

function printPage()
{
	tmpURL = "print.asp?storyid=" + document.getElementById("currentstoryid").value;
	window.open(tmpURL, "null", "height=800,width=630,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes");
}

function sendHomeLink(headline)
{
	tmpURL = "sendHomeLink.asp?pageID=" + document.getElementById("currentpageid").value;
	window.open(tmpURL, null, "height=600,width=800,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

function sendStoryLink()
{
	tmpURL = "includes/sendStoryLink.asp?storyid=" + document.getElementById("currentstoryid").value;
	window.open(tmpURL, null, "height=600,width=800,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

function getEventList(pageid, source)
{

    $.ajax({
        url: "/retrieval/getEventList.aspx?pageid=" + pageid + "&source=" + source,
        cache: false,
        success: function(html)
        {
            $("#mainText").html(html);
        }
    });
}



//--------------------
function showGallery(id)
{
    $.ajax({
        url: "/retrieval/getGallery.aspx?gid=" + id,
        cache: false,
        success: function(html)
        {
            $("#gallery").html(html);
            $("a[rel^='prettyPhoto']").prettyPhoto();
        }
    });
}




function closeGallery()
{
    $("#galleryFrame").hide();
	//document.getElementById("galleryFrame").style.display = "none";
}


//--------------------


function getServiceTimes(id)
{
    $.ajax({
    url: "/retrieval/getServiceTimes.aspx?storyid=" + id,
        cache: false,
        success: function(html)
        {
            $("#serviceTimes").html(html);
        }
    });
}





//------------------------


function resizeVidDiv()
{	
		document.getElementById("mainImage").style.height = "404px";
}

function resizeVidDivShort()
{	
		document.getElementById("mainImage").style.height = "303px";
}

var mainImageDefaultHeight = "203px";
function shrinkMainImageDiv()
{
	document.getElementById("mainImage").style.height = "0px";
	mainImageDefaultHeight = "0px";
}


function shrinkVidDiv()
{	
	document.getElementById("mainImage").style.height = mainImageDefaultHeight;

	if((document.getElementById("hdnvidfile").value != "" && document.getElementById("hdnvidfile").value != "/images/flvvideo/none") || document.getElementById("hdnlcid").value != 0)
	{
		resetVidDiv();
	}
	else
	{
		resetMainImage(document.getElementById("hdnvidimage").value);
	}		
}



function writeNewVideo(file, lcid)
{
    ip = document.getElementById("hdnip").value;
    image = document.getElementById("hdnvidimage").value;
    file = "/images/flvvideo/" + file


    var flashObject = '<object id="flvVideo" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"  width="544" height="306" >'
	+ '          <param name="movie" value="/flash/mainimageplayer.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=play" />'
	+ '          <param name="quality" value="high" />'
	+ '      	 <param name="wmode" value="transparent" />'
	+ '      	 <param name="allowFullScreen" value="true" />'
	+ '          <embed src="/flash/mainimageplayer.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=play" allowFullScreen="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  width="544" height="306" wmode="transparent"></embed>'
	+ '          </object>'

    $("#mainImagePlayer").html(flashObject);
    document.getElementById("header").scrollIntoView();
}

function writeMP3(file, title)
{

    var flashObject = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="192" height="100">'
	+ '    <param name="movie" value="/flash/mp3player.swf?file=' + file + "&title=" + title + '" />'
	+ '    <param name="quality" value="high" />'
	+ '    <param name="wmode" value="transparent" />'
	+ '    <embed src="/flash/mp3player.swf?file=' + file + "&title=" + title + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  width="192" height="100" wmode="transparent"></embed>'
	+ '    </object>'

    $("#mp3Div").css("display", "block");
    $("#mp3Div").html(flashObject);
}

function closeMp3()
{
    $("#mp3Div").css("display", "none");
}




