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];}
}

/**********Tabs***********************/

$(function () {
	var tabContainers = $('div.tabs > div');
	tabContainers.hide().filter(':first').show();
	
	$('div.tabs ul.tabNavigation a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div.tabs ul.tabNavigation a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
});

$(document).ready(function() {
    // Replace numbers with images in news slider
    $(".wslide-menu a").each(function(index) {
        $(this).addClass("numbg"+(index+1))
    });
});


/*
    INTRO
*/
var flash_tag_added = false;
var auto_play_flash = false;
var intro_is_playing = false;

function showIntroWindow(auto_play) 
{
    $("#intro").show();
    adjustIntroWindows()
    addFlashTag();
    if(auto_play) {
        auto_play_flash = true;
        playIntro();
    } else {
         document.location.hash="nointro";
    }
}
function adjustIntroWindows() {
    // scale dark bg to fill all page
    $("#intro_bg").css({width:$(window).width(), height:$(window).height()});
    // center intro window
    var t,l;
    l = $(window).width()/2 - $("#intro_window").width()/2
    t = $(window).height()/2 - $("#intro_window").height()/2
    $("#intro_window").css({top:t, left:l})
    $("#intro_btns").css({top:t+$("#intro_window").height()+10, left:l})
}
function playIntro() {
    $("#intro_img").fadeOut(300);
    setTimeout(function() {
        $(".flashintro").each(function() {
            if(typeof this.startIntro != "undefined") {
                this.startIntro();
                intro_is_playing = true;
            }
        });
    }, 350);
}
function onFlashLoad() {
    if(!auto_play_flash || intro_is_playing) return;
    $(".flashintro").each(function() {
        if(typeof this.startIntro != "undefined") {
            this.startIntro();
            intro_is_playing = true;
        }
    });
}
function skipIntro(dont_show_again) {
    $("#intro").fadeOut(500);
    if(dont_show_again) {
        $.cookie("dont_show_intro", "true");
    }
}
function addFlashTag () {
    var flash_tag = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="990" height="600" id="flashintro" class="flashintro"><param name="movie" value="new-site/swf/introFinal.swf"><param name="wmode" value="transparent"><param name="quality" value="high"><embed src="new-site/swf/introFinal.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="990" height="600" id="flashintro" class="flashintro" wmode="transparent"></embed></object>'
    $("#intro_flash").html(flash_tag);
    flash_tag_added = true;
}
$(window).load(function() {
    if(document.location.href.toLowerCase().indexOf("#forceintro") != -1) {
        $.cookie("dont_show_intro", null);
    }
    if ($.cookie("dont_show_intro") != "true") {
        if(document.location.href.toLowerCase().indexOf("#nointro") == -1) {
            showIntroWindow();
        }
    }
});
$(window).resize(adjustIntroWindows);
