﻿function popupImage( src ){
	window.open( '/ImagePopup.aspx?src=' + src, 'imgPopup', 'width=100,height=100' );
	return false;
}
onload = function(){
	try{
		var allImg = document.getElementsByTagName("img");
		for( var i=0; i<allImg.length; i++ ){
			var img = allImg[i];
			if( img.src.indexOf("_off") > 0 ){
				img.onmouseover = img_mouseover;
				img.onmouseout = img_mouseout;
				var loaderImage = new Image();
				loaderImage.src = img.src.replace('_off','_on');
			}
		}
	}
	catch(e){
	}
}
function img_mouseover(){
	this.src = this.src.replace('_off','_on');
}
function img_mouseout(){
	this.src = this.src.replace('_on','_off');
}

/* google analytics */
( function(){
	try{
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
		var pageTracker = _gat._getTracker("UA-5112642-1");
		pageTracker._initData();
		pageTracker._trackPageview();
	}
	catch(e){
	}
})()

/* youtube links */
$(document).ready(function() {
    initExtLinks();
});

function initExtLinks() {
    var myhost = location.protocol + '//' + location.host;
    var $this, vid, match;
    $('body').find('a[href^=http]').each(function() {
        $this = $(this);
        //old long links
        if ($this.attr("href").indexOf("youtube.com/watch") != -1) {
            match = $this.attr("href").match("[\\?&]v=([^&#]*)");
            if (match.length > 1) {
                vid = match[1];
                popInVideo($this, 'youtube', vid);
            }
        }
        //new shorter links
        if ($this.attr("href").indexOf("youtu.be") != -1) {
            vid = $this.attr("href").substr($this.attr("href").indexOf(".be/")+4);
            popInVideo($this, 'youtube', vid);
        }
    });
}

var currVid;
function popInVideo($this, site, vidID) {
    var swfSrc = (site == "vimeo") ? "http://vimeo.com/moogaloop.swf?clip_id=" + vidID + "&server=vimeo.com&autoplay=1" : "http://www.youtube.com/v/" + vidID + "&hl=en&fs=0&rel=0&autoplay=1";
    $('body').append('<div id="v_' + vidID + '" class="hidden"><div id="' + vidID + '"><div id="swf_' + vidID + '"></div></div></div>');
    $this.colorbox({
        width: 582, height: 396, inline: true, resize: false, href: "#" + vidID
    },
		function() {
		    currVid = vidID;
		    swfobject.embedSWF(
				swfSrc,
				"swf_" + vidID, /* div id */
				560, 340, /* w,h */
				"8.0.0", /* flash version */
				false, /* no express install */
				{}, /* flashvars */
				{allowFullScreen: true, play: true, allowscriptaccess: true }, /* params */
				{} /* attributes */
			);
		    $('#' + vidID).show();
		}
	);
}

//cleanup
$(document).bind('cbox_closed', function() {
    swfobject.removeSWF("swf_" + currVid); //kill container
    $("#" + currVid).html('<div id="swf_' + currVid + '"></div>'); //re-add container
    currVid = null;
});

