// JavaScript Document

if (window.name != "pod") 
{
    window.name = "main";
}


$(document).ready(function()
{
    if ($("#volWrapper").length != 0)
    {
        // initialize tooltip
        $("#volWrapper img[title]").tooltip({
            // tweak the position
            offset: [25, 0],
            position: "top center",
            // use the "slide" effect
            effect: 'slide'
            // add dynamic plugin with optional configuration for bottom edge
        }).dynamic({ bottom: { direction: 'down', bounce: true} });
    }
});

function showGroupItem(item)
{
    $("#" + item).toggle("blind", "fast");
    var itemSplit = item.split("_");

    if ($("#openFlag_" + itemSplit[1]).attr("src") == "/images/groupsListPlus.gif")
    {
        $("#openFlag_" + itemSplit[1]).attr("src", "/images/groupsListMinus.gif");

        //var headerID = item.replace("item", "group");
        //$("#" + headerID).parent().scrollTo("#" + headerID, 800);
    }
    else
    {
        $("#openFlag_" + itemSplit[1]).attr("src", "/images/groupsListPlus.gif");
    }

}


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 openContact(url) 
{

    window.open(url, "Contact", "height=800,width=800,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}



function setConsoleInfo(pageid)
{

    window.parent.currentLocation = "";

    //alert("called");
	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)

}


var tmpLastElement = "";
function makeActive(tmpElement)
{

    window.parent.currentLocation = tmpElement;


    tmpLocationArray = tmpElement.split("_")
    tmpElementID = tmpLocationArray[2];
    tmpStoryID = tmpLocationArray[1];

    if (window.parent.editMode == true)
    {
        if (tmpLastElement != "")
        {
            //alert("last Element = " + tmpLastElement)
            document.getElementById(tmpLastElement).style.backgroundColor = "";
            $("." + tmpLastElement).css("backgroundColor", "");
        }
        tmpLastElement = tmpElement;
        document.getElementById(tmpElement).style.backgroundColor = "#ffcc00";
        $("." + tmpElement).css("backgroundColor", "#ffcc00");

        //alert(tmpElement);
        // alert(document.getElementById(tmpElement).style.backgroundColor);

        window.parent.currStoryId = tmpStoryID;


        window.parent.activeIndicator = tmpElementID;

    }
}

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;
}


function swapVolunteerText(id)
{
    var srcLoc = "#" + id;
    $("#contentWrapper").html($(srcLoc).html());
}


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)-((700+50)/2);
    var PopUpUrl= "evite.aspx?storyid=" + id

	window.open(PopUpUrl,"","width=550,height=700,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");
}

var event_http_request = false;
function getEventList(pageid, source) {
	if(event_http_request) {
		event_http_request.abort();
		event_http_request = false;
	}
	if (window.XMLHttpRequest) { // Mozilla [11], Safari, IE 7
		event_http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE 6-
		event_http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	var url = "/retrieval/getEventList.aspx?pageid=" + pageid + "&source=" + source;
//alert(url);
    event_http_request.onreadystatechange = function(){ writeEvents() };
	event_http_request.open("GET", url, true);
	event_http_request.send(null);

	if (window.parent.document.getElementById("currpageid") != null) 
    {
        window.parent.document.getElementById("currpageid").value = pageid;
    }

}

function writeEvents()
{
	if (event_http_request.readyState == 4)
	{
	    if (event_http_request.status == 200) {
	        document.getElementById("mainText").innerHTML = event_http_request.responseText;
		}
	}
}

var addStory_http_request = false;
function addStory(id)
{
	if(addStory_http_request) {
		addStory_http_request.abort();
		addStory_http_request = false;
	}
	if (window.XMLHttpRequest) { // Mozilla [11], Safari, IE 7
		addStory_http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE 6-
		addStory_http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	var url = "/includes/getStoryBody.asp?storyid=" + id;
	

	addStory_http_request.onreadystatechange = function(){ writeNewStory() };
	addStory_http_request.open("GET", url, true);
	addStory_http_request.send(null);

}

function writeNewStory()
{	
	if (addStory_http_request.readyState == 4)
	{	
		if (addStory_http_request.status == 200)
		{	
			document.getElementById("extraStory").innerHTML = addStory_http_request.responseText;
		}
	}
}


function showGallery2(id)
{
	//document.getElementById("galleryDiv").style.height = "804px";
	//document.getElementById("galleryDiv").style.width = "730px";
	
	var flashObject = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="804" height="730">'
	+ '<param name="movie" value="/gallery.swf?gid=' + id + '">'
	+ '<param name="quality" value="high">'
	+ '	<param name="wmode" value="transparent" />'
	+ '<embed src="/gallery.swf?gid=' + id + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="804" height="730" wmode="transparent"></embed>'
	+ '</object>'
	document.getElementById("galleryDiv").innerHTML = flashObject;
	document.getElementById("galleryDiv").style.display = "block";
	document.getElementById("header").scrollIntoView();
}


//--------------------


var showGallery_http_request = false;
function showGallery(id) {
    if (showGallery_http_request) {
        showGallery_http_request.abort();
        showGallery_http_request = false;
    }
    if (window.XMLHttpRequest) { // Mozilla [11], Safari, IE 7
        showGallery_http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE 6-
    showGallery_http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }

    var url = "/retrieval/getGallery.aspx?gid=" + id;


    showGallery_http_request.onreadystatechange = function() { writeGallery() };
    showGallery_http_request.open("GET", url, true);
    showGallery_http_request.send(null);

}

function writeGallery() {
   
    if (showGallery_http_request.readyState == 4) {

        if (showGallery_http_request.status == 200) {

            document.getElementById("gallery").innerHTML = showGallery_http_request.responseText;
            $("a[rel^='prettyPhoto']").prettyPhoto();
        }
    }
}
//------------------------



function closeGallery()
{
	//document.getElementById("galleryFrame").innerHTML = "";
	//document.getElementById("galleryDiv").style.height = "0px";
	//document.getElementById("galleryDiv").style.width = "0px";
	document.getElementById("galleryFrame").style.display = "none";
}





//This function is deprecated
function checkImage()
{
	if (document.getElementById("SPmiddle").innerHTML == "")
	{
		document.getElementById("SPmiddle").style.height = "0px";
		document.getElementById("SPstoryHolder").style.top = "0px";
	}
}

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 showModal()
{
    //alert("hit")
    $("#contact-container").modal({ onOpen: function(dialog)
    {
        dialog.overlay.fadeIn('fast', function()
        {
            dialog.container.fadeIn('fast', function()
            {
                dialog.data.fadeIn('fast');
            });
        });
    }
    });
}

function hideModal()
{
    $("#contact-container").modal({ onClose: function(dialog)
    {
        dialog.data.slideUp('slow', function()
        {
            dialog.container.slideUp('slow', function()
            {
                dialog.overlay.fadeOut('slow', function()
                {
                    $.modal.close(); // must call this!
                });
            });
        });
    }
    });

}



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)
{
    setNewFullVideo(lcid);
    //shrinkVidDiv();
    /*
    ip = document.getElementById("hdnip").value;
    image = document.getElementById("hdnvidimage").value;
    //wideScreen = document.getElementById("hdniswidescreen").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=8,0,0,0" width="496" height="279">'
	+ '     <param name="movie" value="mainImagePlayervimeo.swf?video=' + file + '&amp;lcid=' + lcid + '&amp;ip=' + ip + '&amp;image=' + image + '" />'
	+ '     <param name="quality" value="high" />'
	+ '     <param name="wmode" value="transparent" />'
	+ '     <param name="allowFullScreen" value="true" />'
	+ '     <embed src="mainImagePlayervimeo.swf?video=' + file + '&amp;lcid=' + lcid + '&amp;ip=' + ip + '&amp;image=' + image + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowFullScreen="true" width="496" height="279" wmode="transparent" ></embed>'
	+ '     </object>'

    document.getElementById("mainImage").innerHTML = flashObject;
    //document.getElementById("headerdiv").scrollIntoView();

*/

}


function resetVidDiv()
{	
	lcid = document.getElementById("hdnlcid").value;
	ip = document.getElementById("hdnip").value;
	image = document.getElementById("hdnvidimage").value;
	file = document.getElementById("hdnvidfile").value;
	//wideScreen = document.getElementById("hdniswidescreen").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="558" height="419" >'
	+ '          <param name="movie" value="mainimagepayer.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=" />'
	+ '          <param name="quality" value="high" />'
	+ '      	 <param name="wmode" value="transparent" />'
	+ '          <embed src="mainimagepayer.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="558" height="419" wmode="transparent"></embed>'
	+ '          </object>'
	
	//alert(flashObject)
	document.getElementById("mainImage").innerHTML = flashObject;

}

function resetMainImage(image) {
    alert("If you see this tell Lee");
	var flashObject = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="539" height="203">'
    + '    <param name="movie" value="mainImage.swf?image=' + image + '" />'
    + '    <param name="quality" value="high" />'
	+ '    <param name="wmode" value="transparent" />'
    + '    <embed src="mainImage.swf?image=' + image + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="539" height="203" wmode="transparent"></embed>'
    + '    </object>'
	document.getElementById("mainImage").innerHTML = flashObject;
}


function showMinistryMenu() {
    document.getElementById("ministryMenu").style.display = "block";
}

function hideMinistryMenu() {
    document.getElementById("ministryMenu").style.display = "none";
}


function openPlayer(cid,id,chid)
{
    var ScreenWidth=window.screen.width;
    var ScreenHeight=window.screen.height;	
    var movefromedge=0;
    placementx=(ScreenWidth/2)-((980)/2);
    placementy=(ScreenHeight/2)-((630+50)/2);
	
    var PopUpUrl= "http://devmedia.aspiredev2.com/mediaplayer/" + cid + "?";
	
	if (id != undefined)
	{
		PopUpUrl += "&id=" + id;
	}
	
	if (chid != undefined)
	{
		PopUpUrl += "&chid=" + chid;
	}
	
	
	window.open(PopUpUrl,"Player","width=980,height=630,toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0,left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
}


function openMe (url) 
{

    window.open(url);
}


function openSame (url) 
{

    window.location.href = (url);
}


function openGoMenu () 
{
	document.getElementById("gomainImage2").style.overflow = "visible";
}

function closeGoMenu () 
{
	document.getElementById("gomainImage2").style.overflow = "hidden";
}


 
    function writeNewVimeoHome(id)
    {
        var newVidString = "<iframe width=\"640\" height=\"360\" frameborder=\"0\""
        newVidString += "src=\"http://player.vimeo.com/video/";
        newVidString += id + "?title=0&byline=0&portrait=0&autoplay=1\"></iframe>";

        showModal();
        $("#homeVideoPlayer").html(newVidString);

        }

        function resetHomeDiv()
        {
        hideModal();    
        $("#homeVideoPlayer").html("");

    }













