//Cufon.replace('h1', { fontFamily: 'Ambroise' });
//Cufon.replace('.menulevel0 > a', { fontFamily: 'Ambroise' });

var mynode, parentnode;
var lastparam = "";
var lastadminparam = "";

var	PanelObj;

function updateOtherRow(val)
{
	if (val == 'Other (specify)')
	{
		document.getElementById('ctl00_ContentPlaceHolder1_otherRow').style.display = 'table-row';
	}
	else
	{
		document.getElementById('ctl00_ContentPlaceHolder1_otherRow').style.display = 'none';
	}
}

function updateHearRow(val)
{
	if (val)
	{
		document.getElementById('ctl00_ContentPlaceHolder1_otherRowA').style.display = 'table-row';
	}
	else
	{
		document.getElementById('ctl00_ContentPlaceHolder1_otherRowA').style.display = 'none';
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function ImageRollOver(inorout, imgobj, imgtype) {
	// int inorout { 1 or 0}	1 = rollover	0 = rollout
	// obj imgobj				the image object
	// str imgtype	{png,jpg,gif,bmp etc}	the filename extension
	if (inorout==1) {
		imgobj.src = imgobj.src.replace("."+imgtype,"-over."+imgtype);
	} else {
		imgobj.src = imgobj.src.replace("-over."+imgtype,"."+imgtype);
	}	
}

function MenuRollOver(inorout, imgobj, imgtype) {
	// int inorout { 1 or 0}	1 = rollover	0 = rollout
	// obj imgobj				the image object
	// str imgtype	{png,jpg,gif,bmp etc}	the filename extension
	if (inorout==1) {
		//imgobj.src = imgobj.src.replace("_grey","_white");
		imgobj.src = imgobj.src.replace("\/Menu\/","\/Menu_Overs\/");
	} else {
		//imgobj.src = imgobj.src.replace("_white","_grey");
		imgobj.src = imgobj.src.replace("\/Menu_Overs\/","\/Menu\/");
	}	
}

function adminSave()
{
	if (eval("typeof " + 'savePage' + " == 'function'")) 
	{ 
		savePage(); 
	} 
	else 
	{
		AdminPanelCallback.callback('save');
	}
}

function delContent(pc,el)
{
	if (confirm('Are you sure you want to delete this content area?'))
	{
		//alert(el);
		document.getElementById('ctl00_ContentPlaceHolder1_' + el).style.display = 'none';
		SavePageContentCallback.callback('delete',pc);
	}
}

function addgallimage(gid)
{
	//alert(gid);
	document.getElementById('gallerynewframe').src = '/blank.aspx?gid=' + gid;
	ShowContentDialog('gallerynewbox',false);
}

function delgimage(gid,iid)
{
	if (confirm('Are you sure you want to delete this image?'))
	{
		//alert(document.getElementById('img' + i).id);
		document.getElementById('img' + iid).style.display = 'none';
		SavePageContentCallback.callback('delgimage',iid);
	}
}

function addsubmenu()
{
	ShowContentDialog('menunewbox',true);
}

function addsubmenunow()
{
	mname = document.getElementById('menuname').value;
	if (mname != '')
	{
		HideContent("menunewbox");
		AdminPanelCallback.callback('addmenu',mynode, mname);
	}
	else
	{
		alert('Please enter a menu name!');
		//ShowContent('menunewbox');
	}
}

function delsubmenu()
{
	if (confirm('Are you sure you want to delete this sub menu and ALL ITEMS WITHIN?'))
	{
		AdminPanelCallback.callback('delmenu',mynode);
	}
}

function SaveContent(contentarea,pc) {
	
	hf2index('ctl00_ContentPlaceHolder1_pcPageAlias','ctl00_ContentPlaceHolder1_HFpcPageAlias');
	
	for ( instance in CKEDITOR.instances ) 
	{
		//alert(instance);
		CKEDITOR.instances[instance].updateElement();
	}
	//alert(contentarea);
	//alert(document.getElementById("ctl00_ContentPlaceHolder1_"+contentarea).innerText);
	//alert(CKEDITOR.instances["ctl00_ContentPlaceHolder1_"+contentarea]);
	if (document.getElementById("ctl00_ContentPlaceHolder1_HF"+contentarea)) 
	{
		document.getElementById("ctl00_ContentPlaceHolder1_HF"+contentarea).value = CKEDITOR.instances["ctl00_ContentPlaceHolder1_"+contentarea].getData();
	}
	//alert(document.getElementById("ctl00_ContentPlaceHolder1_HF"+contentarea).value);
	//alert('Content Saved OK'); 
}

function SaveContentAll(idlist)
{
	SavePageContentCallback.callback('save',idlist);
}

function AddContent (contentarea,pc,contype) {
	//document.getElementById("ctl00_ContentPlaceHolder1_HF"+contentarea).value = '';
	//alert(document.getElementById("ctl00_ContentPlaceHolder1_HF"+contentarea).value);
	//alert('ContentAdded');
	SavePageContentCallback.callback('add',pc,contype);	 
}

function FormSubmit (action) {
	//alert('Form Submitted');
	PageContentCallback.callback(action);	 
}

function FormSubmitBasic (action) {
	//alert('Form Submitted');
	//PageContentCallback.callback(action);	 
	document.getElementById('aspnetForm').submit();
}



function updateParam(sender,eventargs)
{
	lastparam = eventargs.get_parameter();
}

function updateAdminHF(sender,eventargs)
{
//	alert('updateAdminHF sending '+  document.getElementById('ctl00_ContentPlaceHolder1_pcPageTheme').selectedIndex.value());
	lastadminparam = eventargs.get_parameter();
	hf2index('ctl00_ContentPlaceHolder1_pcPageBG','ctl00_ContentPlaceHolder1_HFpcPageBG');
	hf2index('ctl00_ContentPlaceHolder1_pcPageMenuImage','ctl00_ContentPlaceHolder1_HFpcPageMenuImage');
	hf2index('ctl00_ContentPlaceHolder1_pcPageTheme','ctl00_ContentPlaceHolder1_HFpcPageTheme');

}


function PageLoaded()
{
	MM_findObj('MenuArea').visibility = 'visible';
	MM_findObj('MenuArea').style.visibility = 'visible';
	//alert(MM_findObj('MenuArea').visibility);
}

function hf2index(dd,hf)
{
	lc = document.getElementById(dd);
	hfel = document.getElementById(hf);
	if (lc && hfel && !lc.disabled) hfel.value = lc.options[lc.selectedIndex].value;
	//alert(hfel.value);
}




function ToggleChkBx(thecheckbox,thehiddenfield)
{
	if (thecheckbox.checked == 1) {
		document.getElementById("ctl00_ContentPlaceHolder1_"+thehiddenfield).value = 1;
	} else {
		document.getElementById("ctl00_ContentPlaceHolder1_"+thehiddenfield).value = 0;
	}
	//alert(document.getElementById("ctl00_ContentPlaceHolder1_"+thehiddenfield).value);
}


function TreeViewPop_onNodeSelect(sender,eventArgs)
{
	mynode = eventArgs.get_node().get_id();
	parentnode = eventArgs.get_node().get_parentNode().get_id();
	//window.location = '/?PageID=' + mynode;
}

function TreeRightRefresh()
{
}

function ToggleAdminPanel (Panel) {
	$jq("#"+Panel).animate({width:'toggle'},100);
	PanelObj = MM_findObj(Panel);
	//alert(PanelObj.style.width);
	if(PanelObj.style.width=='1px') {
		document.getElementById('adminOpen').innerHTML = "< Admin Panel"
		//AdminPanelCallback.callback('Open');
	}
	else
	{
		document.getElementById('adminOpen').innerHTML = "> Admin Panel"
	}
}

function ToggleAdminPanel2 (Panel) {
	PanelObj = MM_findObj(Panel);
	var POCurLeft = PanelObj.style.marginLeft;
	POCurLeft = POCurLeft.replace('px','');
	//alert(POCurLeft);
	var j = 1;
	if (POCurLeft==0) {
		for (i=POCurLeft;i>=-180;i=i-5) {
			//alert(i);
			j++;
			setTimeout("setMarginLeft("+i+")",j);
		}
	} else {
		for (i=POCurLeft;i++;i<0) {
			j++;
			setTimeout("setMarginLeft("+i+")",j);
		}
	}
	//alert(POCurLeft);
	
}

function setMarginLeft(ml){
	PanelObj.style.marginLeft = ml;
}

<!-- Copyright 2006,2007 Bontrager Connection, LLC
// http://bontragerconnection.com/ and http://www.willmaster.com/
// Version: July 28, 2007
var cX = 0; var cY = 0; var rX = 0; var rY = 0; var offsetX = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX + document.body.scrollLeft; cY = event.clientY + document.body.scrollTop; }
//if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
//else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d,osnow) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
d.style.left = (cX+offsetX+osnow) + "px";
d.style.top = (cY+10) + "px";
}

function AssignPositionC(d,osnow) {
	ceX = 700;
	ceY = 200;
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	ceX += rX; 
	ceY += rY;
	}
d.style.left = (ceX+offsetX+osnow) + "px";
d.style.top = (ceY+10) + "px";
}

function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
//fadeOut(d, 20, 500);
}

function ShowContentDialog(d,move) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
if(move) AssignPosition(dd,0);
//dd.style.display = "block";
fadeIn(d, 20, 10, 500, 20, 500,false);
}

function ShowContent2(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd,150);
//dd.style.display = "block";
fadeIn(d, 20, 200, 2000, 20, 500,false);
}

function ShowContentC(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPositionC(dd,0);
//dd.style.display = "block";
fadeIn(d, 20, 200, 2000, 20, 500,false);
}

//The original javascript came from 
//http://www.sunburnt.com.au/publications/design/javascript-fade-effects
//I modified it to work with my code

//set the opacity of the element (between 0.0 and 1.0)       

function setOpacity(id, level) {
    var element = document.getElementById(id); 
    element.style.display = 'inline';
    element.style.zoom = 1;
    element.style.opacity = level;
    element.style.MozOpacity = level;
    element.style.KhtmlOpacity = level;
    element.style.filter = "alpha(opacity=" + (level * 100) + ");";
}

function fadeIn(id, steps, duration, interval, fadeOutSteps, fadeOutDuration,fo){  
    var fadeInComplete;
    for (i = 0; i <= 1; i += (1 / steps)) {
      setTimeout("setOpacity('" + id + "', " + i + ")", i * duration); 
      fadeInComplete = i * duration;             
    }
    //set the timeout to start after the fade in time and the interval to display the 
    //message on the screen have both completed
	if (fo)
	{
    setTimeout("fadeOut('" + id + "', " + fadeOutSteps + 
               ", " + fadeOutDuration + ")", fadeInComplete + interval);
	}
}

function fadeOut(id, steps, duration) {
    var fadeOutComplete;       
    for (i = 0; i <= 1; i += (1 / steps)) {
      setTimeout("setOpacity('" + id + "', "  + 
                (1 - i) + ")", i * duration);
      fadeOutComplete = i * duration;
    }      
    //completely hide the displayed message after the fade effect is complete
    setTimeout("hide('" + id + "')", fadeOutComplete);
}   

function hide(id){
    document.getElementById(id).style.display = 'none';
}

/*
*
* Define & declare these variables and functions outside the jquery object
* as they are needed for both document.ready and window.load
*
*/

    var video;
    var videoPaused = false;
    var browserWindow = $jq(window);
    var videoRatio;

    function startVideo(videoObj) {
        if ((videoObj.get(0)!=null) &&  (navigator.appName.indexOf("Microsoft") == -1))
		{
			videoObj.get(0).play();
			resizeVideo();
		//	console.log(videoObj);
		}
    }

    function prepVideo() {
        video = $jq('#backgroundVideo');
        startVideo(video);
    }

    
    function scaleVideo(videoObj, w, h) {
        var browserRatio = w / h;
       
        if(h * videoRatio < w) {
            videoObj.get(0).height = w / videoRatio;
            videoObj.get(0).width = w;
        } else if(h * videoRatio > w) {
            videoObj.get(0).height = h;
            videoObj.get(0).width = h * videoRatio;
        }
        
    }
    
    function resizeVideo() {
		if (video.get(0))
		{
        browserWidth = $jq(window).width();//browserWindow.width();
        browserHeight = $jq(window).height();//browserWindow.height();
        videoRatio = video.get(0).videoWidth / video.get(0).videoHeight;
      	scaleVideo(video, browserWidth, browserHeight);
		}
    }
    
