var fonturl ="/wp-content/themes/ek2010/sifr/foliobc.swf";
$(function()
{
    _initFontReplacement();
    _initSwapInput();
    _initTopForm();
});

function _initBuyDvd()
{
    $("#step1 .bluebox div").click(function()
    {
        $("#step1 .bluebox a").removeClass('active');
        $($(this).next()).addClass("active");
        $("#step2 a").removeClass('active');
        $("#step3").hide();
        $("#step2").show();
        return false;
    });
    $("#step2 a").click(function()
    {
        $("#step2 a").removeClass('active');
        $(this).addClass("active");
        
        if ($("#step1 .bluebox a.active").hasClass('institution') && $(this).hasClass('us'))
            {
                window.location = "http://icarusfilms.com/new2010/ek.html";
                return false;
            }

        $("#step3 .substep").hide();
        $("#step3").show();
        $("#step3 .form").empty();
        if ($("#step1 .bluebox a.active").hasClass('individual') && $(this).hasClass('us'))
        {
            $("#step3 #regtype").val('individual-us');
            $(".formcontainer form").clone().prependTo("#step3 .institution-us .form"); 

            $("#step3 .institution-us").show();
            if (lang == 'fr')
            {
                $("#step3 #address-postal").val('zip');
                $("#step3 #address-province").val('état');            }
            else
            {
                $("#step3 #address-postal").val('zip code');
                $("#step3 #address-province").val('state');
            }
        }
            
        if ($("#step1 .bluebox a.active").hasClass('institution') && $(this).hasClass('canada'))
        {
            $(".formcontainer form").clone().prependTo("#step3 .institution-canada .form"); 

            $("#step3 #regtype").val('institution-canada');
            $("#step3 .institution-canada").show();
            if (lang == 'fr')
            {
                $("#step3 #address-postal").val('code postal');
                $("#step3 #address-province").val('province');
            }
            else
            {
                $("#step3 #address-postal").val('postal code');
                $("#step3 #address-province").val('province');
            }
        }
            
        if ($("#step1 .bluebox a.active").hasClass('individual') && $(this).hasClass('canada'))
            $("#step3 .individual-canada").show();
        return false;
    });


}
function _initTopForm()
{
    var srchText = "enter keyword(s)";
    var newsletterText = "enter email";
    if (lang == 'fr')
    {
        srchText = "mots clés";
        newsletterText = "votre courriel";
    }
    $("#topheading form input[name='s']").val(srchText);
    
    $("#topheading .right a").click(function()
    {
        $("#topheading .right a").removeClass('active');
        $(this).addClass('active');
        var active = $("#topheading .right a.active").text().toString().toLowerCase();
        if (active == "newsletter")
            {
                $("#topheading form").attr('target','_blank');
                $("#topheading form").attr('method','post');
                $("#topheading form").attr('action',baseurl+'/newsletter.php?lang='+lang);
                $("#topheading form input[name='s']").val(newsletterText);
            }
            
        else
        {
            $("#topheading form").attr('target','');
            $("#topheading form").attr('method','get');
            $("#topheading form").attr('action',baseurl+'/');
            $("#topheading form input[name='s']").val(srchText);
        }
            


        return false;
    })

}

function _initFontReplacement()
{
    if(typeof sIFR == "function"){
        sIFR.replaceElement(named({
            sSelector:"#content h2,.buydvd h2",
            sFlashSrc:fonturl,
            sColor:"#323232",
            sWmode: "transparent"
        }));

        sIFR.replaceElement(named({
            sSelector:"#rightsidebar h2",
            sFlashSrc:fonturl,
            sColor:"#FFFFFF",
            sWmode: "transparent",
            sCase :"upper",
            sFlashVars: "offsetLeft=12&offsetTop=0&letterSpacing=3"
        }));

        sIFR.replaceElement(named({
            sSelector:" h1,.home_en .producedby, .home_fr .producedby",
            sFlashSrc:fonturl,
            sColor:"#FFFFFF",
            sWmode: "transparent"
        }));
        sIFR.replaceElement(named({
           sSelector: ".buydvd .sifrize a",
           sFlashSrc:fonturl,
           sWmode: "transparent",
           sColor : "#FFFFFF"
        }));
        sIFR.replaceElement(named({
            sSelector:".calendar-month",
            sFlashSrc:fonturl,
            sColor:"#29ABE2",
            sWmode: "transparent",
            sFlashVars: "textalign=center"
        }));
        sIFR.replaceElement(named({
            sSelector:".producedby",
            sFlashSrc:fonturl,
            sColor:"#2471BB",
            sWmode: "transparent",
            sFlashVars: "textalign=left"
        }));
    }
}
/**
 * Search input
 */
function _initSwapInput()
{
    $('#frmtop .swap').each(function() {
	var defaultval = this.value;
        $(this).attr('rel',defaultval);
	$(this).focus(function() {
	    if(this.value == defaultval) {
		this.value = '';
	    }
	});
	$(this).blur(function() {
	    if(this.value == '') {
		this.value = defaultval;
	    }
	});
    });

    $('.buydvd .swap').each(function() {
	var defaultval = this.value;
        $(this).attr('rel',defaultval);
	$(this).focus(function() {
            $(this).css({color: "#0071BC"});
	    if(this.value == defaultval) {
		this.value = '';
	    }
	});
	$(this).blur(function() {
	    if(this.value == '') {
		this.value = defaultval;
                $(this).css({color: "#555"});
	    }
	});
    });
}
