<!--

// Add event for calling function on body load
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

var navVar;
function showSub(navVar) {
	document.getElementById(navVar+'_sub').style.visibility="visible";
}
	
function hideSub(navVar) {
	document.getElementById(navVar+'_sub').style.visibility="hidden";
}

$(function() {
	$.extend($.tooltip.defaults, {
		bodyHandler: function() {
			return '<div class="fg-tooltip fg-tooltip-' + $(this).attr("class") + ' ui-state-error ui-corner-all ui-tiptext">' +
				this.tooltipText + 
		        /*'<div class="fg-tooltip-pointer-down ui-state-error">'
		         '<div class="fg-tooltip-pointer-down-inner"></div>'*/
		        '</div>'
		    '</div>'
		},
		showURL: false,
		fade: true,
		track: true,		
		delay: 0
	});
	$("a.tooltip").tooltip({
		left: -60 
	});
	$("li.tooltip").tooltip({
		bodyHandler: function() {
			return '<div class="fg-tooltip fg-tooltip-' + $(this).attr("class") + ' ui-state-error ui-corner-all ui-tiptext">' +
				this.tooltipText + 
		        '</div>'
		    '</div>'
		},
		left: -60 
	});
});

$(document).ready(function(){	
	MM_preloadImages(siteLoc+'graphics/icon_dreamworkers.gif',siteLoc+'graphics/icon_blog.gif',siteLoc+'graphics/icon_twitter.gif',siteLoc+'graphics/icon_digg.gif',siteLoc+'graphics/icon_news.gif',siteLoc+'graphics/icon_caseStudies.gif',siteLoc+'graphics/icon_download.gif',siteLoc+'graphics/icon_webmail.gif',siteLoc+'graphics/icon_sitemap.gif',siteLoc+'graphics/icon_gtalk.gif',siteLoc+'graphics/icon_yahoo.gif',siteLoc+'graphics/icon_skype.gif',siteLoc+'graphics/icon_msn.gif',siteLoc+'graphics/icon_email.gif',siteLoc+'graphics/icon_post.gif',siteLoc+'graphics/icon_phone.gif',siteLoc+'graphics/icon_mobile.gif',siteLoc+'graphics/icon_prev_blue.png',siteLoc+'graphics/icon_next_blue.png',siteLoc+'graphics/icon_play_blue.png',siteLoc+'graphics/icon_pause_blue.png',siteLoc+'graphics/nav_hover_bg_6.gif',siteLoc+'graphics/graphics/icon_information.png',siteLoc+'graphics/graphics/icon_Acrobat.gif');
    //thickbox replacement
    var closeModal = function(hash)
    {
        var $modalWindow = $(hash.w);
        $modalWindow.fadeOut('2000', function()
        {
            hash.o.remove();
            if (hash.refreshAfterClose === 'true')
            {
                window.location.href = document.location.href;
            }
        });
    };
    var openInFrame = function(hash)
    {
        var $trigger = $(hash.t);
        var $modalWindow = $(hash.w);
        var $modalContainer = $('iframe', $modalWindow);
        var myUrl = $trigger.attr('href');
        var myTitle = $trigger.attr('title');
        var newWidth = 0, newHeight = 0, newLeft = 0, newTop = 0;
        $modalContainer.html('').attr('src', myUrl);
        //$('#jqmTitleText').text(myTitle);
        myUrl = (myUrl.lastIndexOf("#") > -1) ? myUrl.slice(0, myUrl.lastIndexOf("#")) : myUrl;
        var queryString = (myUrl.indexOf("?") > -1) ? myUrl.substr(myUrl.indexOf("?") + 1) : null;

        if (queryString != null && typeof queryString != 'undefined')
        {
            var queryVarsArray = queryString.split("&");
            for (var i = 0; i < queryVarsArray.length; i++)
            {
                if (unescape(queryVarsArray[i].split("=")[0]) == 'width')
                {
                    var newWidth = queryVarsArray[i].split("=")[1];
                }
                if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'height')
                {
                    var newHeight = queryVarsArray[i].split("=")[1];
                }
                if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'title')
                {
                    var newTitle = queryVarsArray[i].split("=")[1];
					$('#jqmTitleText').text(newTitle);
                }
                if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'jqmRefresh')
                {
                    // if true, launches a "refresh parent window" order after the modal is closed.

                    hash.refreshAfterClose = queryVarsArray[i].split("=")[1]
                } else
                {

                    hash.refreshAfterClose = false;
                }
            }
            // let's run through all possible values: 90%, nothing or a value in pixel
            if (newHeight != 0)
            {
                if (newHeight.indexOf('%') > -1)
                {

                    newHeight = Math.floor(parseInt($(window).height()) * (parseInt(newHeight) / 100));

                }
                var newTop = Math.floor(parseInt($(window).height() - newHeight) / 2);
            }
            else
            {
                newHeight = $modalWindow.height();
            }
            if (newWidth != 0)
            {
                if (newWidth.indexOf('%') > -1)
                {
                    newWidth = Math.floor(parseInt($(window).width() / 100) * parseInt(newWidth));
                }
                var newLeft = Math.floor(parseInt($(window).width() / 2) - parseInt(newWidth) / 2);

            }
            else
            {
                newWidth = $modalWindow.width();
            }

            // do the animation so that the windows stays on center of screen despite resizing
            $modalWindow.css({
                width: newWidth,
                height: newHeight,
                opacity: 0
            }).jqmShow().animate({
                width: newWidth,
                height: newHeight,
                top: newTop,
                left: newLeft,
                marginLeft: 0,
                opacity: 1
            }, 'slow');
        }
        else
        {
            // don't do animations
            $modalWindow.jqmShow();
        }

    }
	//width=90%&height=50%&jqmRefresh=true
    $('#modalWindow').jqm({
        overlay: 50,
        modal: true,
        trigger: 'a.thickbox',
        target: '#jqmContent',
        onHide: closeModal,
        onShow: openInFrame
    });
	$('#modalWindow').jqDrag();

});
