// JavaScript Document

/* ############################################################ */
/* 					general sifr code	 			    */
/* ############################################################ */

	sIFR.delayCSS  = true;

	var myriad = { src: '/_flash/myriadPro.swf' };
		sIFR.activate(myriad);

	/*sIFR.replace(myriad, {
		selector: 'h3'
		,css: [
		  '.sIFR-root { text-align: center; font-weight: bold; }'
		  ,'a { text-decoration: none; }'
		  ,'a:hover { text-decoration: underline; }'
		]
	  });*/


/* ############################################################ */
/* 					left nav sifr (navigation)	 			    */
/* ############################################################ */

	sIFR.replace(myriad, {
		selector: '.leftMenuNav h2'
		,css: [
			'.sIFR-root { color: #3F382E; font-weight:bold; leading:-7; font-size: 20px; line-height:8px; letter-spacing:-0.5; }'
			,'.subTitle { font-size:60px; font-weight:normal; letter-spacing:0.5;}'
			,'a { text-decoration: none; color: #3F382E; }'
			,'a:hover { color: #7B6C59;}'
		]
	});
	
	sIFR.replace(myriad, {
		selector: '.leftMenuSubNav'
		,css: [
			'a { color: #000000; font-size: 80px; line-height:8px; letter-spacing:0.25; leading:-4; text-decoration:none;}'
			,'a:hover { color: #7B6C59; text-decoration:underline;}'
		]
	});
	
	/*sIFR.replace(myriad, {
		selector: '.leftMenuNav h2 a:hover'
		,css: {
		  '.sIFR-root' : '{ text-decoration: underline; color: #3F382E; color: #3F382E; font-weight:bold; leading:-7; font-size: 20px; line-height:8px; letter-spacing:-0.5; }'
		  ,'.subTitle' : '{ font-size:60px; font-weight:normal; letter-spacing:0.5;}'
		}
		,filters: {
			DropShadow: {
				knockout: true
				,distance: 1
				,color: '#330000'
				,strength: 2
			}
		}
	}*/


/* ############################################################ */
/* 						contact us form 						*/
/* ############################################################ */

function CheckForm(FormObject) {
	errorColor = "yellow";

	for (i=0; i<FormObject.elements.length; i++)
	{
		FormObject.elements[i].style.backgroundColor = "white";
		if(FormObject.elements[i].getAttribute('required') == "true")
		{
			if(FormObject.elements[i].value == "")
			{
				alert("You forgot to fill out your " + FormObject.elements[i].getAttribute('message'));
				FormObject.elements[i].style.backgroundColor = "yellow";
				FormObject.elements[i].focus();
				return false;
			}
		}
	}
	return true;
}

/* ############################################################ */
/* 						main body ajax slider					*/
/* ############################################################ */

function getPage(someURL, forceLoad, returnFalse, urlVars){
	if (forceLoad == null) {
		forceLoad = false;
	}
	
	if (returnFalse == null) {
		returnFalse  = false;
	}
	
	if (urlVars == null) {
		urlVars = "";
	}

	
	if ( (someURL == currentURL) && (!forceLoad) ) {
		return;
	}
	
	var historyURL = "/_historyFrame.cfm?targetURL=" + someURL + "&showTemplate=false" + urlVars;
	$("historyFrame").src = historyURL;
	
	//bodySlider.toggle().chain(function(){
	//bodyContentFx.setStyles({'overflow':'hidden'}).chain(function(){
		//myAjax = new Ajax(someURL + "?showTemplate=false", {method: 'get', onComplete: updateBody});
		//myAjax.request();
	//});

	if (returnFalse) {
		return false;
	}
}

function updateBody(newText, newURL, scriptText) {
	/* set the hash mark */
	currentURL = newURL;
	location.hash = currentURL;
	
	/* find out how large the new content is */
	if (newText != "") {
		$("bodyContentMeasurer").setHTML(newText);
	} else {
		newText = $("bodyContentMeasurer").innerHTML;
	}

	var measuredHeight = parseInt($("bodyContentMeasurer").offsetHeight);

	// resize the shadow
	var bodyPadding = 127;
	bodyShadowFx.start({'height': measuredHeight + bodyPadding});

	// resize the frame to that new height
	bodyContentFx.start({'height': measuredHeight, 'opacity':0,/*'color': '#F2F1EF',*/ 'padding-left': '10px'}).chain(function(){
		var bodyContent = $("bodyContent");																									   
		// set it up for the motion
		bodyContent.setStyles({'padding-left' : '50px'});
		
		// set the text
		bodyContent.setHTML(newText);
		$("bodyContentMeasurer").empty();

		// get the title if there is one
		getTitle(bodyContent);

		// if theres a script then run it
		if (scriptText == null) { scriptText = ""; }
		if (scriptText != "") { eval(scriptText); }
		
		// and show the next text in the new height
		bodyContentFx.start({'opacity':[0,1],/* 'color': '#000',*/ 'padding-left': '20px'}).chain(function(){
			if (document.all) {
				bodyContent.style.removeAttribute("opacity");
				bodyContent.style.removeAttribute("filter");
			}
		});
	});
	//bodySlider.toggle();
}

var windowTitle = "OutDash Development";
function getTitle(someObject) {
	var titles = $ES('.pageTitle', someObject);
	
	if (titles.length == 1) {
		document.title = windowTitle + " - " + titles[0].getText();
	} else {
		document.title = windowTitle + "";
	}
}

	
/* ############################################################ */
/* 							logo sifr 	 			    		*/
/* ############################################################ */

	sIFR.replace(myriad, {
		selector: '#companyLogo'
		,css: [
		  '.sIFR-root { text-indent:10px; color: #3F382E; font-weight:bold; leading:-21; font-size: 34px; letter-spacing:-0.5; width: 500px;}'
		  ,'#companyLogo .subTitle { text-indent:40px; font-size:30px; font-weight:normal; letter-spacing:2.5; text-transform:capitalize;}'
		  ,'a { text-indent:10px; color: #3F382E; font-weight:bold; leading:-21; font-size: 34px; letter-spacing:-0.5; width: 500px;}'
		]
	  });





/* ############################################################ */
/* 					code for opening transition 			    */
/* ############################################################ */

function slideInOtherPanels() {
	var leftMenuFX = $("leftMenuPanel").effects({duration: 1500, transition: Fx.Transitions.Bounce.easeOut
});
	var testimonialFX = $("testimonialPanel").effects({duration: 2000, transition: Fx.Transitions.linear});

	bodyPanelFX = $("bodyPanel").effects({duration: 1500, transition: Fx.Transitions.Circ.easeInOut});
	bodyPanelFX.start({'top': '0px'});
	
	leftMenuFX.start({'border-bottom-width': '15px', 'padding-top': '30px', 'height': '220px'}).chain(function(){
			testimonialFX.start({'opacity': 1});
			$("bodyShadowPanel").setStyles({'display': ''});
			
			// load the content of the page
			//if (currentURL == myHash) {
				// if we are already on the right page, 
				// then just put the stuff from the template into the body
				//updateBody("",currentURL);
			//} else {
				// otherwise, load the content
				getPage(myHash, true);
			//}
		});
}

function slideInBackmostPanel() {
	$("pageLoadingImg").setStyle("display","none");
	hideEverythingStyleSheet.disabled = true;
	
	var backmostPanelFX = $("backmostPanel").effects({duration: 1000, transition: Fx.Transitions.Circ.easeInOut});
	backmostPanelFX.start({'width': '750px'}).chain(function(){
		slideInOtherPanels();
	});

	subNavOvers();

}

function showEverything() {
	$("leftMenuPanel").setStyles({'border-bottom-width': '15px', 'padding-top': '30px', 'height': '220px'});
	$("bodyPanel").setStyles({'top': '0px'});
	$("backmostPanel").setStyles({'width': '750px'});
	$("testimonialPanel").setOpacity( 1 );
	$("bodyShadowPanel").setStyles({'display': ''});
	
	// load the content of the page
	//if (currentURL == myHash) {
		//updateBody("",currentURL);
	//} else {
		getPage(myHash, true);
	//}
}

var myHash = location.hash.substring(1);
if (myHash == "") {
	myHash = "/index.cfm";	
}







/* ############################################################ */
/* 					inner navigation on pages					*/
/* ############################################################ */


function findAncestor(someObject, someClass) {
	if (someObject.getParent() == null) {
		return null;
	}
	
	if (someObject.getParent().className == someClass) {
		return someObject.getParent();
	}
	
	return findAncestor( someObject.getParent(), someClass );
}

function scrollToPage(someLink) {
	var pageID = someLink.getAttribute("targetID");
	
	var pageGrandparent = findAncestor( $(someLink), "pageContent");
	var innerNavGrandparent = findAncestor( $(someLink), "innerNav");
	
	var allLinks = $ES('a', innerNavGrandparent);
	
	allLinks.each(function(thisLink) {
		if (thisLink == someLink) {
			thisLink.addClass("active");
		} else {
			thisLink.removeClass("active");
		}
	});
	
	var pagePanel = $E('.pages',pageGrandparent);
	
	var thisPage = $E("#" + pageID,pagePanel);
	//alert(thisPage.outerHTML);
	//alert( thisPage.getPosition().y );
	
	var myScroller = new Fx.Scroll(pagePanel, {
		wait: false,
		duration: 500,
		offset: {'x': 0, 'y': 0},
		transition: Fx.Transitions.Quad.easeInOut
	});

	myScroller.toElement(thisPage);
	
	return false;
}