/* 
flash requirements() 
~ onclick="function();return false"
*/
function review(url) {
    newwindow = window.open(url,'review','"toolbar=no,address=no,left=150,top=150,status=no,width=550,height=400,scrollbars=yes,resizable=yes"')
}
function news(url) {
    newwindow = window.open(url,'news','"toolbar=no,address=no,left=150,top=150,status=no,width=550,height=400,scrollbars=yes,resizable=yes"')
}
function contact() {
    newwindow = window.open('contact.php','privacy','"toolbar=no,address=no,left=150,top=50,status=no,width=550,height=850,scrollbars=yes,resizable=yes"')
}
function privacy() {
    newwindow = window.open('privacy.php','privacy','"toolbar=no,address=no,left=150,top=150,status=no,width=550,height=550,scrollbars=yes,resizable=yes"')
}
function terms() {
    newwindow = window.open('terms.php','terms','"toolbar=no,address=no,left=130,top=130,status=no,width=550,height=550,scrollbars=yes,resizable=yes"')
}
function subscribe() {
    newwindow = window.open('contact.php?subscribe=true','subscribe','"toolbar=no,address=no,left=150,top=50,status=no,width=550,height=850,scrollbars=yes,resizable=yes"')
}

// @params	currentSection = current section loaded, prevents continuous reloads
var currentSection = 'home';
var currentContent = '#home';

//window.setTimeout(doFirstPage,9000);
//other funcs
// standard javascript for identifying flash file by object id
function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

//scroll to div...
function scrollWindow(target) 
{
	$('#'+target).ScrollTo(1000);
}

//open page as flash would...
function doPage(pageVSize, mainPage, subPage, speed)
{
	setSection(mainPage, subPage);
	resizeEl("#flashContent", pageVSize, speed);
	if (mainPage == 'privacy') {
		$('#top').ScrollTo(1);
	} else if (mainPage == 'terms') {
		$('#top').ScrollTo(1);
	}
	urchinTracker(mainPage);
	return false;
}

function doPageOverride(addr,title)
{
	//SWFAddress.setValue('/'+mainPage+'/');
	getFlashMovie("website").doSwfAddress(addr,title);
}

var doFirstPage = function() {
	doPage(400, currentSection, currentContent, 0);
};

// Public
function getUserAgent() {
	return navigator.userAgent;
}
// Public
/*function setSection(section) {
	currentSection = section;
}*/

// Public
function getSection() {
	return currentSection;
}

//Public
function setSection(section, selector)
{

	if(selector == '') {
		selector = '#home';
	} else {
		selector = '#'+selector;
	}
	selector = '#home';
	if(currentContent != null && currentContent != selector)
	{
		animSel = currentContent;
		$(currentContent).animate({
			height: 0
		}, 1000, "easeIn", function() { $(animSel).hide(); $(animSel).height('auto') } );
	}
	
	if(section != currentSection) {
		currentContent = null;
		//insert preloader here
		if ((section == 'demo') || (section == 'home')) {
			//page = 'content/'+section+'_alt.html';
			page = 'content/'+section+'.php';
		} else {
			page = 'content/'+section+'.php';
		}
		$('#loadContent').load(page,{},function() { showContent(selector); } );
	} else {
		showContent(selector);
	}
	currentSection = section;
}

// Public
// @params	selector	= css selector of the element to resize
//			height		= new height of the element
//			speed		= speed of resize and delay of callback to flash
function resizeEl(selector, height, speed) {
	/*if (getUserAgent().indexOf("Firefox") == -1) {*/
		if(!speed){speed=500};
		$(selector).animate({
		height: height
		}, speed, "easeIn", _tellFlash("resizeEl(selector="+selector+", height="+height+", speed="+speed+") Done", speed));
	/*} else {
		speed = 0;
		$(selector).height(height);
		_tellFlash("resizeEl(selector="+selector+", height="+height+", speed="+speed+") Done", speed)
	}*/
}
// Private
// @params	sleep		= passed from calling function, time to wait before calling broadcast
// @todo
function _tellFlash(msg, sleep) {
	
	setTimeout("_broadcast('"+msg+"')", sleep);
}
// Private
// @params	msg			= message to tell flash
// @todo maybe pass a function to call in flash
function _broadcast(msg) {
	// change this to pass a message to flash instead of the div
}

function showContent(selector) {
	if(selector != currentContent && $(selector) != null)
	{
		$(".contain").css("background-image", "none"); 

		var animSel = currentContent;
		
		var ht = $(selector).height() + 10;
		//$(selector).css('opacity', 0);
		$(selector).height('1px');
		$(selector).show();
		
		$(selector).animate({
			height: ht, opacity: 1
		}, 1000, "easeIn" );
		
		currentContent = selector;
	}
}