var MIN_WIDTH 			= 640;
var MAX_WIDTH			= 1100;
var background_width 	= 0;
var background_height 	= 0;

function addEvent(object, eventName, callback){ 
	// attempt to add an event listener
	if (object.addEventListener){ 
		object.addEventListener(eventName, callback, false); 
		return true; 
	} 
	// if this fails, attach an event
	else if (object.attachEvent){ 
		return object.attachEvent("on"+eventName, callback); 
	} 
	// if this fails, indicate
	else { 
		return false; 
	} 
}
function resizeBackground() {
	// set up percentages (of the viewport) for the background image
	var percentHeight = 0.80;
	var percentWidth = 0.90;
	
	// the large backgrounds dimensions
	
	
	// locate the background
	var element = document.getElementById('background');
	if (!element) {
		element = document.getElementById('background_small');
		percentHeight = 0.415;
	}
	if (element) {
		// determine the dimensions
		var backgroundWidth 	= background_width;
		var backgroundHeight 	= background_height;
		var ratioHeight 		= backgroundWidth / backgroundHeight;
		var ratioWidth 			= backgroundHeight / backgroundWidth;
		var viewport 			= getViewport();
		
		// scale depending on how much room we have
		
		if (viewport.width > viewport.height) {
			backgroundWidth = (viewport.width * percentWidth);
			backgroundHeight = backgroundWidth * ratioWidth;
		}
		else {
			backgroundHeight = (viewport.height * percentHeight);
			backgroundWidth = backgroundHeight * ratioHeight;
		}
		
		// check to see if the min or max was reached was reached
		if (backgroundWidth < MIN_WIDTH || backgroundWidth > MAX_WIDTH) {
			backgroundWidth = backgroundWidth < MIN_WIDTH ? Math.max(backgroundWidth,MIN_WIDTH) : Math.min(backgroundWidth,MAX_WIDTH);
			backgroundHeight = backgroundWidth * ratioWidth;
		}
		
		// resize the background
		element.style.width = backgroundWidth + "px";
		element.style.height = backgroundHeight + "px";
		
		// resize the body if needed
		element = document.getElementById('body');
		if (element) 
			element.style.width = backgroundWidth + "px";
		
	}
}
function skipIntro() {
/*
	var windowUrl = window.location.href;
	if (windowUrl.indexOf("?") == -1)
		window.location.replace(windowUrl + "?skip_intro=true");
	else 
		window.location.replace(windowUrl + "&skip_intro=true");*/
	window.location = "home.html";
	//window.location.href = "home.html";
}
function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}

function getViewport() {
	var object = window, parameter = 'inner';
	if ( !( 'innerWidth' in window ) ) {
		parameter = 'client';
		object = document.documentElement || document.body;
	}
	return { width : object[ parameter+'Width' ] , height : object[ parameter+'Height' ] }
}
function onResize() {
	resizeBackground();
}

function onLoad() {

	// set the dimensions of the backgruond
	var element = document.getElementById('background');
	if (!element)
		element = document.getElementById('background_small');
	if (element) {
		// save the dimensions
		background_width 	= element.clientWidth;
		background_height 	= element.clientHeight;
		
		// resize the background
		resizeBackground();
	}

	// check for mobile browsers
	var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
    if (!mobile) {  
	
        // allow resizing
		if (element)
			addEvent(window,'resize',onResize);
		
		// get ready to add the movie by locating the movies div
		var element = document.getElementById('flash_content');
	
		if (element) {
			// set up the parameters
			var flashvars = {
			  location: "images/flash/rr2.swf"
			};
			var params = {
			  menu: "false",
			  wmode: "transparent",
			  allowScriptAccess:"sameDomain",
			  scale: "showall"
			};
			var attributes = {};
			
			// determine the dimensions
			var movieWidth = 640;
			var movieHeight = 480;
			
			var movieAspectRatio = movieWidth / movieHeight;
			movieHeight = element.clientHeight;
			movieWidth = movieHeight * movieAspectRatio;
			
			// add the movie
			swfobject.embedSWF("images/flash/IntroLoader.swf", "flash_content", movieWidth, movieHeight, "9.0.0","images/flash/expressInstall.swf", flashvars, params, attributes);
			
		}
	}
}

// wait for the window to load
addEvent(window,'load',onLoad);
	

	
  



