$(document).ready(function () {
	Global.init();
	popup.init();
}); 
var Global = 
{
	init: function () {
           
		this.doSIFR();
		this.doEffects();
		this.styleSwitcher();
	}
	,
	doSIFR: function () {
		if (typeof sIFR == "function")
		{
            if (requiredSIFRColour == undefined)
            {
                requiredSIFRColour = '#E27329';
            }
		        var currLoc = currentLocale.toUpperCase();
		        var requiredFlashSource = "/flash/poplar_all.swf";
        
		        //If you need to add a locale that needs to use Impact, 
		        //add the locale to the array below. see below for cyrillic char sets
		        var accentLocales = ['ES-ES', 'FR-BE', 'NL-BE', 'NL-NL', 'HU-HU', 'FR-FR', 'DE-DE', 'FR-CA'];

                if (jQuery.inArray(currLoc, accentLocales) < 0) {            
                    requiredFlashSource = "/flash/poplar_all.swf";
                }
                else {                    
                    requiredFlashSource = "/flash/impact_all.swf";
                }
                
                var requiredcase = "upper";

			var Header = named({
			    
		        sFlashSrc:	requiredFlashSource,
		        sColor:		requiredSIFRColour,
		        sCase: requiredcase,
		        sWmode: "transparent",
		        sFlashVars:	""
			});
			var HeaderSm = named({
				sFlashSrc:	"/flash/stoneSans_all.swf",
				sColor:		requiredSIFRColour,
				sWmode: "transparent",
				sFlashVars:	""
			});
			var HeaderHome = named({
				sFlashSrc:	requiredFlashSource,
				sColor:		"#FFFFFF",
				sCase: requiredcase,
				sWmode: "transparent",
				sFlashVars:	""
			});
			var HeaderHomeSm = named({
				sFlashSrc:	requiredFlashSource,
				sColor:		"#3a7eb7",
				sCase: requiredcase,
				sWmode: "transparent",
				sFlashVars:	""
			});
			var HeaderHomeSmDrk = named({
				sFlashSrc:	requiredFlashSource,
				sColor:		"#043453",
				sCase: requiredcase,
				sWmode: "transparent",
				sFlashVars:	""
			});
			// replace elements
    			//add cyrillic locales to this array
		        var cyrillicLocales = ['RU-RU', 'EL-GR', 'SL-SI', 'PL-PL'];
			        
                if (jQuery.inArray(currLoc, cyrillicLocales) < 0) {
			        sIFR.replaceElement('#page #contentCol h1', Header);
			        sIFR.replaceElement('#page #contentCol h2', HeaderSm);
			        sIFR.replaceElement('#page #contentCol h4', HeaderSm);
			        sIFR.replaceElement('#maincontent h1', HeaderHome);
			        sIFR.replaceElement('#maincontent h2', HeaderHomeSm);
			        sIFR.replaceElement('#maincontent h2.drk', HeaderHomeSmDrk);
                }
                else {
                    $('.sIFR-hasFlash #contentCol h1, .sIFR-hasFlash #contentCol h2, .sIFR-hasFlash #contentCol h3, .sIFR-hasFlash #contentCol h4, #contentCol h1, #contentCol h2, #contentCol h3, #contentCol h4, #contentCol h5').css( {"visibility": "visible", "color": requiredSIFRColour} );
                }
                $('#contentCol h1, #contentCol h2, #contentCol h3, #contentCol h4, #contentCol h5').css( {"visibility": "visible", "color": requiredSIFRColour} );
		};
	}
	,
	doEffects: function () {

	    
		//hover states for li's
		$("#topNav li, #leftNav li").hover(
		function(){
   			$(this).addClass("hover");
 		},
		function(){
			$(this).removeClass("hover");
 		});
		//add click state for poll
		 $("ul.articlepoll li a").hover(
		 function(){
		   $(this).removeClass("hover");
		 },
		 function(){
		   $(this).addClass("hover");
		 });

		//stripe tables - consumer
		$('table.striped tr:even, table.con-orange-3col tr:even').css('background', '#fdf6d9');
		$('table.striped tr:odd, table.con-orange-3col tr:odd').css('background', '#fbf0bd');
    
        //HCP - light blue
		$('table.topicList-hcp-blue tr:even').css('background', '#FFFFFF');
		$('table.topicList-hcp-blue tr:odd').css('background', '#f0f6fb');

        //HCP - light green
		$('table.topicList-hcp-green tr:even').css('background', '#FFFFFF');
		$('table.topicList-hcp-green tr:odd').css('background', '#f4f6e9');		

        //HCP/Media - dark blue
		$('table.mediaList2col tr:even, table.mediaList4col tr:even').css('background', '#FFFFFF');
		$('table.mediaList2col tr:odd, table.mediaList4col tr:even').css('background', '#f1f6fc');
		
		$('li.print a').click( function(e) {
		    window.print();	
		    e.preventDefault();
		    dcsMultiTrack('DCS.dcsuri','/print_page.link','WT.ti','Print page','WT.cg_n','Action','WT.cg_s','Print page', 'DCSext.brand', 'Flora', 'DCSext.site', 'Checkforchange');
		});
		
	}
	,
	styleSwitcher: function () {
	
		$('#switcher span a').click(function () {
			$('body').removeClass();
				if (this.id == 'reg') {
					$('body').addClass('reg');
				}
				else if (this.id == 'L') {
					$('body').addClass('large');
				}
				else if (this.id == 'XL') {
					$('body').addClass('extralarge')
				}
			$('#switcher span a').removeClass('selected');
			$(this).addClass('selected');
		});
	}
}	

var popup = 
{
    init: function() {
        
        //Tell a friend popup
        $('li.tell a').click(function (e) {
            popup.close("#popup-nws");
            popup.launch("#popup-tell");
            e.preventDefault();
            dcsMultiTrack('DCS.dcsuri','/send_to_a_friend.link','WT.ti','Tell a friend','WT.cg_n','Action','WT.cg_s','Tell a friend', 'DCSext.brand', 'Flora', 'DCSext.site', 'Checkforchange');
        });
        
        $('a.tell').click(function (e) {
            popup.close("#popup-nws");
            popup.launch("#popup-tell");
            e.preventDefault();
            dcsMultiTrack('DCS.dcsuri','/send_to_a_friend.link','WT.ti','Tell a friend','WT.cg_n','Action','WT.cg_s','Tell a friend', 'DCSext.brand', 'Flora', 'DCSext.site', 'Checkforchange');
        });
        
        //Tell a friend popup div
        $('div.tell a').click(function (e) {
            popup.close("#popup-nws");
            popup.launch("#popup-tell");
            e.preventDefault();
            dcsMultiTrack('DCS.dcsuri','/send_to_a_friend.link','WT.ti','Tell a friend','WT.cg_n','Action','WT.cg_s','Tell a friend', 'DCSext.brand', 'Flora', 'DCSext.site', 'Checkforchange');
        });
        
        //Newsletter popup
        $('a.newsLaunch').click(function (e) {
            popup.close("#popup-tell");
            popup.launch("#popup-nws");
            e.preventDefault();
        });
        $("#popup-nws .close").click(function (e) { 
            popup.close("#popup-nws");
            e.preventDefault();
        });
        $("#popup-tell .close").click(function (e) { 
            popup.close("#popup-tell");
            e.preventDefault();
        });
    }
    ,
    launch: function(selector) {
        $('.popup h1, .popup h2').css( {"visibility": "visible", "color": requiredSIFRColour} )
		$(selector).css( {"visibility": "visible", "z-index": "8000"} );
		$(selector + " h1").css( {"display": "block"} );	
		$(selector + " h2").css( {"display": "block"} );
		$(selector + " p").css( {"display": "block"} );

        var accentLocales = ['ES-ES', 'FR-BE', 'NL-BE', 'NL-NL', 'HU-HU', 'FR-FR', 'DE-DE', 'FR-CA'];
		var currLoc = currentLocale.toUpperCase();

        if (jQuery.inArray(currLoc, accentLocales) < 0) {            
            requiredFlashSource = "/flash/poplar_all.swf";
        }
        else {                    
            requiredFlashSource = "/flash/impact_all.swf";
        }

	    //reload sifr on popup
	    if (requiredSIFRColour == undefined) {
            requiredSIFRColour = '#E27329';
        }
	    if (typeof sIFR == "function")
	    {                
		    var Header = named({
			    sFlashSrc:	requiredFlashSource,
			    sColor:		requiredSIFRColour,
			    sCase: "upper",
			    sWmode: "transparent",
			    sFlashVars:	""
		    });
		    var HeaderH2 = named({
			    sFlashSrc:	requiredFlashSource,
			    sColor:		requiredSIFRColour,
			    sWmode: "transparent",
			    sFlashVars:	""
		    });

        currLoc = currentLocale.toUpperCase();
        var locales = ['RU-RU', 'EL-GR', 'SL-SI', 'PL-PL'];
	        
            if (jQuery.inArray(currLoc, locales) < 0) {
		        sIFR.replaceElement(selector + " h1", Header);
		        sIFR.replaceElement(selector + " h2", HeaderH2);
            }
            else {
                $('.popup h1, .popup h2').css( {"visibility": "visible", "color": requiredSIFRColour} );
            }
		    
	    }
	}
	,    
	close: function (selector) {
		$(selector).css( {"visibility": "hidden", "z-index": "1"} );
		$(selector + " h1").css( {"display": "none", "visibility": "hidden"} );
		$(selector + " h2").css( {"display": "none", "visibility": "hidden"} );
		$(selector + " p").css( {"display": "none"} );
			

    }
}