// quirksmode browser detect
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "preloadCssImages"
 * by Scott Jehl, scott@filamentgroup.com
 * http://www.filamentgroup.com
 * reference article: http://www.filamentgroup.com/lab/automated_image_preloading/
 * demo page: http://www.filamentgroup.com/examples/preloadImages/
 * 
 * Copyright (c) 2008 Filament Group, Inc
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 *
 * Version: 1.0, 31.05.2007
 * Changelog:
 * 	02.20.2008 initial Version 1.0
 * --------------------------------------------------------------------
 */
$.preloadCssImages = function(settings){
	//overrideable defaults
	settings = jQuery.extend({
		 imgDir: 'images'
	}, settings);

	//dump all the css rules into one string
	var sheets = document.styleSheets;
	var cssPile = '';
	for(var i = 0; i<sheets.length; i++){
		if(!$.browser.msie){
			var thisSheetRules = document.styleSheets[i].cssRules;
			for(var j = 0; j<thisSheetRules.length; j++){
				cssPile+= thisSheetRules[j].cssText;
			}
		}
		else {
			cssPile+= document.styleSheets[i].cssText;
		}
	}
	//parse string for image urls and load them into the DOM
	var allImgs = [];//new array for all the image urls  
	var imgUrls = cssPile.match(/[^\/]+\.(gif|jpg|jpeg|png)/g);//reg ex to get a string of between a "/" and a ".filename"
	if(imgUrls != null && imgUrls.length>0 && imgUrls != ''){//loop array
		var arr = jQuery.makeArray(imgUrls);//create array from regex obj	 
		$(arr).each(function(k){
			allImgs[k] = new Image(); //new img obj
			allImgs[k].src = settings.imgDir +'/'+ this;	
		});
	}
	return allImgs;
}

/*
 *
 *	jQuery Timer plugin v0.1
 *		Matt Schmidt [http://www.mattptr.net]
 *
 *	Licensed under the BSD License:
 *		http://mattptr.net/license/license.txt
 *
 */
 
 jQuery.timer = function (interval, callback)
 {
 /**
  *
  * timer() provides a cleaner way to handle intervals  
  *
  *	@usage
  * $.timer(interval, callback);
  *
  *
  * @example
  * $.timer(1000, function (timer) {
  * 	alert("hello");
  * 	timer.stop();
  * });
  * @desc Show an alert box after 1 second and stop
  * 
  * @example
  * var second = false;
  *	$.timer(1000, function (timer) {
  *		if (!second) {
  *			alert('First time!');
  *			second = true;
  *			timer.reset(3000);
  *		}
  *		else {
  *			alert('Second time');
  *			timer.stop();
  *		}
  *	});
  * @desc Show an alert box after 1 second and show another after 3 seconds
  *
  * 
  */

	var interval = interval || 100;

	if (!callback)
		return false;
	
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		
		this.internalCallback = function () {
			callback(self);
		};
		
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		
		var self = this;
	};
	
	return new _timer(interval, callback);
 };
 
 
// <![CDATA[
if (document.getElementById('flashcontent') != null)  {
  var so = new SWFObject("../main.swf?flv_path=http://www.mstudio.com/client/ces/demo_v1/videos/2012.flv", "root", "352", "220", "9", "#000000");
  so.addParam("quality", "high");
  so.addParam("menu", "false");
  so.addParam('scale', 'noscale');
  so.addParam('allowFullScreen', 'true');
  so.addParam('salign', 'lt');
  so.addParam("bgcolor", "#000000");
  so.write("flashcontent");
}
// ]]>


function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') { 
		  windowHeight = window.innerHeight;
		  //windowHeight = screen.availHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
  //alert (BrowserDetect.version + BrowserDetect.browser);
	return windowHeight;
}
		
function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
		  var contentHeight = "";
		  
			if (document.getElementById('content-everywhere') != null) {
      contentHeight = document.getElementById('content-everywhere').offsetHeight;
			} 
      
      if (document.getElementById('content') != null)  {
			contentHeight = document.getElementById('content').offsetHeight;
      } // end if

			var footerGradientElement = document.getElementById('bottom');
			var footerGradientHeight  = footerGradientElement.offsetHeight;
			
			//alert ("IE body height" + document.body.clientHeight);
			//alert ("IE contentHeight" + contentHeight);
						
			if (windowHeight - (contentHeight + footerGradientHeight) >= 0) {
				footerGradientElement.style.position = 'absolute';
				footerGradientElement.style.top = (windowHeight - footerGradientHeight) + 'px';
			}
			else {
        if (BrowserDetect.version == "6" && BrowserDetect.browser == "Explorer") {
          contentTempHeight = contentHeight + footerGradientHeight;
          //alert (contentTempHeight);
          if (contentTempHeight > 2500) {
            //alert ("here 1");
            footerGradientElement.style.position = 'absolute';
				    footerGradientElement.style.top = ((windowHeight + (contentTempHeight - 900))) + 'px';
          }
          else if (contentTempHeight > 1600) {
            //alert ("here 1");
            footerGradientElement.style.position = 'absolute';
				    footerGradientElement.style.top = ((windowHeight + (contentTempHeight - (contentTempHeight / 2)))) + 'px';
          } else if (windowHeight < contentTempHeight) {
            //alert ("here 2");
            footerGradientElement.style.position = 'absolute';
				    footerGradientElement.style.top = (contentTempHeight) + 'px';
				  } else {
				    footerGradientElement.style.position = 'static';
          }
        } else {
				footerGradientElement.style.position = 'static';
				}
			}
		}
	}
}
window.onload = function() {
	setFooter();
}

// booth carousel
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        vertical: true,
        scroll: 1
    });
});

function changeImage (imageID, caption) {
  if (imageID != "") {
    document.getElementById('swap-image').innerHTML = '<img src="images/' + imageID + '" width="511" height="341" alt="' + imageID + '">';
    document.getElementById('caption').innerHTML = caption;
  } // end if
} // end function