// JavaScript Document
var $j = jQuery.noConflict();
$j(document).ready(function() { 
	$j.ifixpng('i/pixel.gif');
	$j('div#SiteTitle').ifixpng();
	$j('div#YSC-Promo h2').ifixpng();
	$j('a.cta').ifixpng();
	
	$j('h2.sosa-title').ifixpng();
	$j('div.sidepromo').ifixpng();
	
	$j(".lab1, .lab2").bind("click", function() {
		$j.fancybox({
			'href' : $j(this).attr('href'),
			'width' : 760,
			'height' : 500,
			'autoScale' : false,
			'transitionIn' : 'none',
			'transitionOut' : 'none',
			'type' : 'iframe'
		});
		$j("#fancybox-frame").css("margin-top", "-32px");
		return false;
	});
	
	$j(".video-box").bind("click", function() {
		$j.fancybox({
			'href' : $j(this).attr('href'),
			'width' : 860,
			'height' : 400,
			'autoScale' : false,
			'transitionIn' : 'none',
			'transitionOut' : 'none',
			'type' : 'iframe'
		});
		return false;
	});
	
	$j(".video-box-no-description").bind("click", function() {
		$j.fancybox({
			'href' : $j(this).attr('href') + "&removeDescription=1",
			'width' : 390,
			'height' : 400,
			'autoScale' : false,
			'transitionIn' : 'none',
			'transitionOut' : 'none',
			'type' : 'iframe'
		});
		return false;
	});
	
	
	$j(".interactive-box").bind("click", function() {
		$j.fancybox({
			'href' : $j(this).attr('href'),
			'width' : 840,
			'height' : 600,
			'autoScale' : false,
			'transitionIn' : 'none',
			'transitionOut' : 'none',
			'type' : 'iframe'
		});
		return false;
	});
	
	$j(".itimeline, .iexploration").bind("click", function() {
		$j.fancybox({
			'href' : $j(this).attr('href'),
			'width' : 790,
			'height' : 525,
			'scrolling': 'no',
			'autoScale' : true,
			'transitionIn' : 'none',
			'transitionOut' : 'none',
			'type' : 'iframe'
		});
		return false;
	});
	
	/*$j("#nine-12").bind("click", function() {
		$j.fancybox({
			'href' : $j(this).attr('href'),
			'width' : 480,
			'height' : 300,
			'autoScale' : false,
			'transitionIn' : 'none',
			'transitionOut' : 'none',
			'type' : 'iframe',
			'scrolling' : 'no'
		});
		$j("#fancybox-frame").css("margin-top", "auto");
		return false;
	});
	$j(".interactives #nine-12").unbind("click");*/

	
	$j(".whelmers").bind("click", function() {
		$j.fancybox({
			'href': $j(this).attr('href'),
			'width': 562,
			'height': 395,
			'autoscale': false,
			'transitionIn' : 'none',
			'transitionOut' : 'none',
			'type' : 'iframe',
			'scrolling' : 'no'		
		});
		return false;
	});
	
	$j("#signup").bind("click", function() {
		$j.fancybox({
			'href': '/views/signup.cfm',
			'width': 500,
			'height': 525,
			'autoscale': false,
			'transitionIn' : 'none',
			'transitionOut' : 'none',
			'type' : 'iframe',
			'scrolling' : 'no'		
		});
		return false;
	});

	$j(".local-lab").bind("click", function() {
		$j.fancybox({
			'href': $j(this).attr('href'),
			'width': 760,
			'height': 500,
			'autoscale': false,
			'transitionIn' : 'none',
			'transitionOut' : 'none',
			'type' : 'iframe',
			'scrolling' : 'no'		
		});
		return false;
	});
	
}); 



function closeFB() {
	$j.fancybox.close();
}


// ExternalInterface.call from swf
function launchFlashMovie(caller) {
	switch (caller) {
		case "timeline":
			$j(".itimeline").click();
			break;
		case "virtuallab1":
			$j(".lab1").click();
			break;
		case "virtuallab2":
			$j(".lab2").click();
			break;
		case "virtuallab3":
			$j(".local-lab").click();
			break;
		case "exploration":
			$j(".iexploration").click();
			break;
		default:
			return false;
	}
}
 
function popupWindow(url,width,height)
{
	// set the width and height of the playlist popup window to be created
	popupWidth = width;
	popupHeight = height;
	popupURL = url;
	// attempt to determine the width and height of the user's current window - default to 800x600
	windowWidth = 800;
	windowHeight = 600;
	try {
		if (self.innerWidth) {
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (parent.document.documentElement && parent.document.documentElement.clientWidth) {
			windowWidth = parent.document.documentElement.clientWidth;
			windowHeight = parent.document.documentElement.clientHeight;
		} else if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (parent.document.body) {
			windowWidth = parent.document.body.clientWidth;
			windowHeight = parent.document.body.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
	} catch(err) {
		windowWidth = 800;
		windowHeight = 600;
	}

	// determine the position of our popup window based on the current window size
	popupLeft = (windowWidth/2)-(popupWidth/2);
	popupTop = (windowHeight/2)-(popupHeight/2);

	myUrl = popupURL;
	myTarget = "refPopupWindow";
	myArgs = 'width='+popupWidth+',height='+popupHeight+',location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,hotkeys=0,top='+popupTop+',left='+popupLeft;
	refPopupWindow = window.open( myUrl, myTarget, myArgs );
	refPopupWindow.focus();
}
 
function getIsIE()
{
	var av=navigator.appVersion;
	var ua=navigator.userAgent.toLowerCase();
	var isIE=((typeof window.ActiveXObject!="undefined") && (av.indexOf('MSIE')!=-1));
	return isIE;
	var is6=(parseInt(av.substring(av.indexOf('MSIE')+4))==6)
	return isIE&&is6;
}	
		
function getIsIE6()
{
	var av=navigator.appVersion;
	var ua=navigator.userAgent.toLowerCase();
	var isIE=((typeof window.ActiveXObject!="undefined") && (av.indexOf('MSIE')!=-1));
	var is6=(parseInt(av.substring(av.indexOf('MSIE')+4))==6)
	return is6;
}	

/*
 * jQuery ifixpng plugin
 */
;(function($) {

	/**
	 * helper variables and function
	 */
	$.ifixpng = function(customPixel) {
		$.ifixpng.pixel = customPixel;
	};
	
	$.ifixpng.regexp = {
		bg: /^url\(["']?(.*\.png([?].*)?)["']?\)$/i,
		img: /.*\.png([?].*)?$/i
	},
	
	$.ifixpng.getPixel = function() {
		return $.ifixpng.pixel || 'images/pixel.gif';
	};
	
	var hack = {
		base	: $('base').attr('href'),
		ltie7	: $.browser.msie && $.browser.version < 7,
		filter	: function(src) {
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src='"+src+"')";
		}
	};
	
	/**
	 * Applies ie png hack to selected dom elements
	 *
	 * $('img[@src$=.png]').ifixpng();
	 * @desc apply hack to all images with png extensions
	 *
	 * $('#panel, img[@src$=.png]').ifixpng();
	 * @desc apply hack to element #panel and all images with png extensions
	 *
	 * @name ifixpng
	 */
	 
	$.fn.ifixpng = hack.ltie7 ? function() {
		function fixImage(image, source, width, height, hidden) {
			image.css({filter:hack.filter(source), width: width, height: height})
			  .attr({src:$.ifixpng.getPixel()})
			  .positionFix();
		}
		
    	return this.each(function() {
			var $$ = $(this);
			if ($$.is('img') || $$.is('input')) { // hack image tags present in dom
				var source, img;
				if (this.src && this.src.match($.ifixpng.regexp.img)) { // make sure it is png image
					// use source tag value if set 
					source = (hack.base && this.src.substring(0,1)!='/' && this.src.indexOf(hack.base) === -1) ? hack.base + this.src : this.src;
					// If the width is not set, we have a problem; the image is not probably visible or not loaded
					// and we need a work around.
					if (!this.width || !this.height) {
						$(new Image()).one('load', function() {
							fixImage($$, source, this.width, this.height);
							$(this).remove();
						}).attr('src', source);
					// If the image already has dimensions (it's loaded and visible) we can fix it straight away.
					} else fixImage($$, source, this.width, this.height);
				}
			} else if (this.style) { // hack png css properties present inside css
				var imageSrc = $$.css('backgroundImage');
				// Background repeated images we cannot fix unfortunately
				if (imageSrc && imageSrc.match($.ifixpng.regexp.bg) && this.currentStyle.backgroundRepeat == 'no-repeat') {
					imageSrc = RegExp.$1;
					var x = this.currentStyle.backgroundPositionX || 0, y = this.currentStyle.backgroundPositionY || 0;
					if (x || y) {
						var css = {}, img;
						if (typeof x != 'undefined') {
							if (x == 'left') css.left = 0; 
							// if right is 0, we have to check if the parent has an odd width, because of an IE bug
							else if (x == 'right') css.right = $$.width() % 2 === 1 ? -1 : 0;
							else css.left = x;
						}
						if (typeof y != 'undefined') {
							// if bottom is 0, we have to check if the parent has an odd height, because of an IE bug
							if (y == 'bottom') css.bottom = $$.height() % 2 === 1 ? -1 : 0; 
							else if (y == 'top') css.top = 0;
							else css.top = y;
						}
						img = new Image();
						$(img).one('load', function() {
							var x,y, expr = {}, prop;
							// Now the image is loaded for sure, we can see if the background position needs fixing with an expression (in case of percentages)
							if (/center|%/.test(css.top)) {
								expr.top = "(this.parentNode.offsetHeight - this.offsetHeight) * " + (css.top == 'center' ? 0.5 : (parseInt(css.top) / 100));
								delete css.top;
							}
							if (/center|%/.test(css.left)) {
								expr.left = "(this.parentNode.offsetWidth - this.offsetWidth) * " + (css.left == 'center' ? 0.5 : (parseInt(css.left) / 100));
								delete css.left;
							}
							// Let's add the helper DIV which will simulate the background image
							$$.positionFix().css({backgroundImage: 'none'}).prepend(
								$('<div></div>').css(css).css({
									width: this.width,
									height: this.height,
									position: 'absolute',
									filter: hack.filter(imageSrc)
								})
							);
							if (expr.top || expr.left) {
								var elem = $$.children(':first')[0];
								for (prop in expr) elem.style.setExpression(prop, expr[prop], 'JavaScript');
							}
							$(this).remove();
						});
						img.src = imageSrc;
					} else {
						$$.css({backgroundImage: 'none', filter:hack.filter(imageSrc)});
					}
				}
			}
		});
	} : function() { return this; };
	
	/**
	 * positions selected item relatively
	 */
	$.fn.positionFix = function() {
		return this.each(function() {
			var $$ = $(this);
			if ($$.css('position') != 'absolute') $$.css({position:'relative'});
		});
	};

})(jQuery);
