 var frutiger = {
  src: 'global/swf/frutiger45Light.swf'
  ,ratios: [10, 1.32, 16, 1.27, 19, 1.23, 25, 1.22, 30, 1.21, 32, 1.19, 33, 1.2, 37, 1.19, 38, 1.2, 51, 1.19, 55, 1.18, 56, 1.19, 84, 1.18, 86, 1.17, 88, 1.18, 89, 1.17, 90, 1.18, 93, 1.17, 94, 1.18, 1.17]
};
 var frutigerRoman = {
  src: 'global/swf/frutiger55roman.swf'
  ,ratios: [8, 1.41, 11, 1.31, 15, 1.29, 25, 1.25, 33, 1.23, 43, 1.22, 61, 1.21, 91, 1.2, 92, 1.19, 107, 1.2, 108, 1.19, 110, 1.2, 113, 1.19, 115, 1.2, 119, 1.19, 120, 1.2, 121, 1.19, 122, 1.2, 124, 1.19, 1.2]
};
 var frutigerLightCon = {
  src: 'global/swf/sifr.swf'
  ,ratios: [10, 1.32, 16, 1.27, 23, 1.23, 24, 1.21, 25, 1.22, 31, 1.21, 38, 1.2, 42, 1.19, 43, 1.2, 51, 1.19, 55, 1.18, 56, 1.19, 94, 1.18, 98, 1.17, 100, 1.18, 104, 1.17, 105, 1.18, 110, 1.17, 111, 1.18, 1.17]
};

sIFR.activate(frutiger);
sIFR.activate(frutigerRoman);
sIFR.activate(frutigerLightCon);
//sIFR.debug.ratios({ src: 'global/swf/frutiger47LightCondensed.swf', selector: 'p.sifrbold' });

sIFR.replace(frutiger, {
	selector: 'h1',
	css: [
        '.sIFR-root { color: #ffffff; }'
      ]
});
sIFR.replace(frutiger, {
	selector: 'fieldset h2',
	css: [
        '.sIFR-root { color: #665D4A; font-weight: bold;}'
      ]
});
sIFR.replace(frutigerLightCon, {
	selector: 'p.sifrbold',
	css: [
        '.sIFR-root { color: #665D4A; font-weight: bold; }'
      ]
})

$(document).ready(function(){

    //shadowbox
	links = [];
	$(".shadowbox-flipbook").each(
		function(i)
		{
			/*swap the href and rel attributes*/
			href = $(this).attr("href");
			rel = $(this).attr("rel");
			$(this).attr("href", rel);
			$(this).attr("rel", href);
			links[i] = this;
		}
		
	);
	if(links.length > 0)
	{
	    Shadowbox.init({
		    loadingImage: 		'global/img/shadowbox/loading.gif',
		    overlayBgImage:     '',
		    overlayOpacity:     1
	    });
		Shadowbox.setup(links, {showTitle: true, titleHeight: "20px"});
	}
	links = [];
	//shadow2
		links2 = [];
	$(".shadowbox-flipbook2").each(
		function(i)
		{
			/*swap the href and rel attributes*/
			href = $(this).attr("href");
			rel = $(this).attr("rel");
			$(this).attr("href", rel);
			$(this).attr("rel", href);
			links2[i] = this;
		}
		
	);
	if(links2.length > 0)
	{
	    Shadowbox.init({
		    loadingImage: 		'global/img/shadowbox/loading.gif',
		    overlayBgImage:     '',
		    overlayOpacity:     1
	    });
		Shadowbox.setup(links2, {showTitle: true, titleHeight: "20px"});
	}
	links2 = [];
	
	
	$(".shadowbox").each(
		function(i)
		{
			links[i] = this;
		}
	);
	if(links.length > 0)
	{
	    Shadowbox.init({
		    loadingImage: 		'global/img/shadowbox/loading.gif',
		    overlayBgImage:     '',
		    overlayOpacity:     0.90
	    });
		Shadowbox.setup(links, {showTitle: true, titleHeight: "20px"});
	}

    if(document.getElementById("popup-gallery"))
    {
        //see if theres an attribute for which gallery needs to be showing on load
        loc = window.location + "";
        if(loc.indexOf("&gallery")!==-1)
        {
            si = loc.indexOf("&gallery") + 9;
            li = loc.indexOf("&", si);
            if(li < 0){li = loc.length;}
            id = loc.substring(si, li);
            
            $("div.popup-gallery div.tab-container").addClass("hidden");
            $("div.popup-gallery div#"+id).removeClass("hidden");
            $("div.popup-gallery div.tabs li").removeClass("selected");
            $("div.popup-gallery div.tabs li."+id).addClass("selected");
        }
        //set up controls for each gallery
        $("#popup-gallery div.tab-container").each(
            function(i)
            {
                count = 0;
                $(this).children(".item").each(
                    function()
                    {
                        count++;
                    }
                );
                html = "Item <span class='curr'>1</span> of <span class='total'>" + count + "</span>";
                $(this).children(".controls").children(".count").children("p").html(html);
            }
        );
	    //tabs swap
	    $("#popup-gallery div.tabs ul li a").click(
	        function()
	        {
	            id = $(this).attr("href").replace("#", "");
	            $("div.tab-container").addClass("hidden");
	            $("div.tabs ul li").removeClass("selected");
	            $(this).parents("li").addClass("selected");
	            $("#"+id).removeClass("hidden");
	            return false;
	        }
	    );
	    //next behaviour
	    $("#popup-gallery div.tab-container div.controls div.next a").click(
	        function()
	        {
	            if(!($(this).parents(".next").attr("class").match("next-disabled")))
	            {
	                //get the current gallery id
	                id = $(this).parents(".tab-container").attr("id");
	                //get the number of the current showing element
	                num = parseInt($("#"+id+" div.controls div.count span.curr").html())-1;
	                next = num+1;
	                
	                //animate the images	   
                    //updates the count after fade complete         
                    $("#"+id+" div.item:eq("+num+")").fadeOut(2000, function(){$("#"+id+" div.controls div.count span.curr").html(next+1);});
                    $("#"+id+" div.item:eq("+next+")").fadeIn(2000);
    	            
    	            
	                total = parseInt($("#"+id+" div.controls div.count span.total").html());
	                if((next+1) == total)
	                {
	                    $("#"+id+" div.controls div.next").addClass("next-disabled");
	                }
	                if(next == 1)
	                {
	                    $("#"+id+" div.controls div.prev").removeClass("prev-disabled");
	                }
	            }
	            return false;
	        }
	    );
    	
	    //prev behaviour
	    $("#popup-gallery div.tab-container div.controls div.prev a").click(
	        function()
	        {
	            if(!($(this).parents(".prev").attr("class").match("prev-disabled")))
	            {
	                //get the current gallery id
                    id = $(this).parents(".tab-container").attr("id");
                    //get the number of the current showing element
                    num = parseInt($("#"+id+" div.controls div.count span.curr").html())-1;
                    next = num-1;
                    
                    //animate the images	            
                    //updates the count after fade complete
                    $("#"+id+" div.item:eq("+num+")").fadeOut(2000, function(){$("#"+id+" div.controls div.count span.curr").html(next+1);});
                    $("#"+id+" div.item:eq("+next+")").fadeIn(2000);
                    
                    
                    total = parseInt($("#"+id+" div.controls div.count span.total").html());
                    if(next == 0)
                    {
                        $("#"+id+" div.controls div.prev").addClass("prev-disabled");
                    }
                    if(next < total)
                    {
                        $("#"+id+" div.controls div.next").removeClass("next-disabled");
                    }
                }
                return false;
	        }
	    );
	}
	
	/*ie6 input button hover*/
	$("input.btnsubmit").hover(
	    function()
	    {
	        $(this).addClass("btnsubmit-hover");
	    },
	    function()
	    {
	        $(this).removeClass("btnsubmit-hover");
	    }
	);
	
});

function closeShadowbox()
{
    parent.Shadowbox.close();
}
