// JavaScript Document

//(function($) {
//    var cache = [];
//    // Arguments are image paths relative to the current page.
//    $.preLoadImages = function() {
//        var args_len = arguments.length;
//        for (var i = args_len; i--; ) {
//            var cacheImage = document.createElement('img');
//            cacheImage.src = arguments[i];
//            cache.push(cacheImage);
//        }
//    }
//})(jQuery)

//jQuery.preLoadImages("/images/campushome/sampleHome.jpg", "/images/campushome/heavy_01.jpg", "/images/campushome/bantam_01.jpg", "/images/campushome/bantam_02.jpg", "/images/campushome/heavy_02.jpg", "/images/campushome/bantam_04.jpg");




function pageWide()
{
	$("#sidebar").css("display", "none");
}



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;
}

//$(document).ready(function()
//{
//    $("#pageButton-1").addClass("pageButtonRoll");
//});

var prevDiv = "#pageDiv-1";
var prevButton = "#pageButton-1";


function swapPage(objID)
{
    var divIndex = objID.charAt(objID.length - 1);
    var obj = "#pageDiv-" + divIndex;
    var button = "#pageButton-" + divIndex;

    $(obj).css("display", "block");
    $(button).addClass("pageButtonRoll");


    if (obj != prevDiv)
    {
        $(prevDiv).css("display", "none");
        $(prevButton).removeClass("pageButtonRoll");
    }

    prevButton = "#pageButton-" + divIndex;
    prevDiv = "#pageDiv-" + divIndex;
}




var campusSelectState = "closed";
function openCampusSelect()
{
    if (campusSelectState == "closed")
    {
        $("#campusSelectDiv").slideDown("slow");
        campusSelectState = "open";
    }
    else
    {
        $("#campusSelectDiv").slideUp("slow");
        campusSelectState = "closed";
    }
}






function tmpPopup(url) 
{
    window.open(url, null, "height=600,width=800,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

function openContact(url)
{

    window.open(url, "Contact", "height=650,width=760,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 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() {
//		$("#tabs").tabs({
//			event: 'mouseover'
//		});
//	});



function toggleDiv(div)
{
    $("#"+div).toggle("fast");
}

function toggleSeries(id)
{

    if ($("#button_" + id).attr("src") == "/images/misc/sermons" + id + ".gif")
    {
        $("#button_" + id).attr("src", "/images/misc/sermons" + id + "_b.gif");
    }
    
    else
    {
        $("#button_" + id).attr("src", "/images/misc/sermons" + id + ".gif");
    }
    
    $("#week" + id).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;
    }
}


//Moved to core.js
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 getGroupsList(pageid, source)
{
    $.ajax({
        url: "/retrieval/getGroupsList.aspx?pageid=" + pageid + "&source=" + source,
        cache: false,
        success: function(html) {
            $("#mainText").html(html);
        }
    });
}


function showGroupItem(item) {
    $("#" + item).toggle("blind","fast");

}


function openItem(id) {

    if (itemOpen != id) {
        $("#mainText").accordion("activate", $("#" + id))
    }
    itemOpen = id;

}


//--------------------
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 resizeStreamDiv(newHeight)
{
    $("#mainImagePlayerStream").animate({ height: 360 }, 250)
}


function shrinkStreamDiv()
{
    $("#mainImagePlayerStream").animate({ height: 180 }, 250)
	resetStreamDiv();
}



function resizeVidDiv(newHeight)
{
    $("#mainImagePlayer").animate({ height: newHeight }, 250)
}


function shrinkVidDiv()
{
    $("#mainImagePlayer").animate({ height: 180 }, 250)
	
}


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="568" height="426" >'
	+ '          <param name="movie" value="/flash/mainImagePlayer.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=play" />'
	+ '          <param name="quality" value="high" />'
	+ '          <param name="allowFullScreen" value="true" />'
	+ '      	 <param name="wmode" value="transparent" />'
	+ '          <embed src="/flash/mainImagePlayer.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=play" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  allowFullScreen="true" width="568" height="426" wmode="transparent"></embed>'
	+ '          </object>'

    $("#mainImagePlayer").html(flashObject);
    
    document.getElementById("header").scrollIntoView();

}




function writeNewStream(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="640" height="360" >'
	+ '          <param name="movie" value="/flash/mainImagePlayerStream.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=play" />'
	+ '          <param name="quality" value="high" />'
	+ '          <param name="allowFullScreen" value="true" />'
	+ '      	 <param name="wmode" value="transparent" />'
	+ '          <embed src="/flash/mainImagePlayerStream.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=play" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  allowFullScreen="true" width="640" height="360" wmode="transparent"></embed>'
	+ '          </object>'
    
	//$("#holder").scrollTop(100);
    $("#mainImagePlayerStream").html(flashObject);
	$("#mainImagePlayerStream").animate({ height: 360 }, 250)
    //scrollTop($("#header"));
	document.getElementById("header").scrollIntoView();
	

}


function resetStreamDiv()
{
    shrinkVidDiv();
    lcid = document.getElementById("hdnlcid").value;
    ip = document.getElementById("hdnip").value;
    image = document.getElementById("hdnvidimage").value;
    file = document.getElementById("hdnvidfile").value;

    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="640" height="360" >'
	+ '          <param name="movie" value="/flash/mainImagePlayerStream.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=" />'
	+ '          <param name="quality" value="high" />'
	+ '      	 <param name="wmode" value="transparent" />'
	+ '          <embed src="/flash/mainImagePlayerStream.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="640" height="360" wmode="transparent"></embed>'
	+ '          </object>'
    $("#mainImagePlayerStream").html(flashObject);
	$("#mainImagePlayerStream").animate({ height: 360 }, 250)

}





function resetVidDiv()
{
    shrinkVidDiv();
    lcid = document.getElementById("hdnlcid").value;
    ip = document.getElementById("hdnip").value;
    image = document.getElementById("hdnvidimage").value;
    file = document.getElementById("hdnvidfile").value;

    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="568" height="426" >'
	+ '          <param name="movie" value="/flash/mainImagePlayer.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=" />'
	+ '          <param name="quality" value="high" />'
	+ '      	 <param name="wmode" value="transparent" />'
	+ '          <embed src="/flash/mainImagePlayer.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="568" height="426" wmode="transparent"></embed>'
	+ '          </object>'
    $("#mainImagePlayer").html(flashObject);

}		
		

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="250" height="120">'
	+ '    <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="250" height="120" wmode="transparent"></embed>'
	+ '    </object>'

    $("#mp3Div").css("display", "block");
    $("#mp3Div").html(flashObject);
}

function closeMp3()
{
    $("#mp3Div").css("display", "none");
}


function closeMap()
{
	document.getElementById("mapDiv").style.display = "none";
}

function openMap()
{
	document.getElementById("mapDiv").style.display = "block";
}

