/* setup font for sifr */
var helvlight = {
    src: 'swf/helvlight.swf'
};

// You probably want to switch this on, but read <http://wiki.novemberborn.net/sifr3/DetectingCSSLoad> first.
sIFR.useStyleCheck = true;
sIFR.activate(helvlight);

sIFR.replace(helvlight, {selector: 'h1',wmode: 'transparent',
                         css: '.sIFR-root { color: #333333; margin-bottom: 0; letter-spacing: -0.1 }'
});

/*
sIFR.replace(helvlight, {selector: 'h2',wmode: 'transparent',
                         css: '.sIFR-root { font-size: 20px; color: #1DA0D2; margin-bottom: 0 }'
});
*/
sIFR.replace(helvlight, {selector: '.blackh2',wmode: 'transparent',
                         css: '.sIFR-root { font-size: 20px; color: #111111; margin-bottom: 0 }'
});
sIFR.replace(helvlight, {selector: 'h3',wmode: 'transparent',
                         css: '.sIFR-root { font-size: 15px; color: #1DA0D2; letter-spacing: -0.1 }'
});

function resizeBackground() {
    $("#promo").css({"width":$('body').width(),"height":$('body').height()});
    $("#promo_content").css({"margin":"100px auto"});
};

var resizeTimer = null;
$(window).bind('resize', function() {
    if (resizeTimer) clearTimeout(resizeTimer);
    resizeTimer = setTimeout(resizeBackground, 50);

});

$(document).ready(function() {
    //$("#promo").css({width:$('body').width(),height:$('body').height(),visibility:"visible"});
    //$("#promo_content").animate({opacity:1},{duration:1000});

    $(".close_btn").click(function() {
        $("#promo").animate({'opacity':0},500,hidePromo);
    });

    function hidePromo() {
        $("#promo").css({'visibility':'hidden'});
    }

    /* initialise quote and contact form validation */
    $("#quick_contact").validate();
    $("#quoteform").validate();
    $("#contactform").validate();
    $("#webupload").validate();
    // $("#form_subscribe").validate();

    /* set up tooltips */
    $(function(){
        $('label.tip').tooltip({
            track: true,
            delay: 0,
            animation: {opacity:'show'},
            showURL: true,
            showBody: " - ",
            opacity: 0.95,
            top: 15,
            left: 15
        });
        $('label.tip').bgiframe();
    });

    /* hide 'other' options in quote form */
    for(var i=1;i<6;i++) {
        $("#option"+i).hide();
    }

    // init tabs for fsc page
    $('#fsc > ul').tabs({ fx: { opacity: 'toggle',duration: 150 }});

    // $("#tab_1 img").mouseover(function () { $(this).fadeTo("fast", 0.5) });
    /*
    for(var i=1;i<10;i++) {
        $("#tabImg_"+i).hover(function(){
            $(this).fadeTo("medium", 0.4); // This sets the opacity to 100% on hover
        },function(){
            $(this).fadeTo("fast", 1); // This sets the opacity back to 60% on mouseout
        });
    }
    */

    $("#quote_jobdesc").change(
                        function(){
                            var selected = this.options[this.selectedIndex].text;
                            if(selected == "Other") {
                                $("#option1 input").addClass("required");
                                $("#option1").show(200);
                            } else {
                                $("#option1 input").removeClass("required");
                                $("#option1").hide(200);
                            }
    });
    $("#quote_weight").change(
                        function(){
                            var selected = this.options[this.selectedIndex].text;
                            if(selected == "Other") {
                                $("#option2 input").addClass("required");
                                $("#option2").show(200);
                            } else {
                                $("#option2 input").removeClass("required");
                                $("#option2").hide(200);
                            }
    });
    $("#quote_colours").change(
                        function(){
                            var selected = this.options[this.selectedIndex].text;
                            if(selected == "Other") {
                                $("#option3").show(200);
                                $("#option3 input").addClass("required");
                            } else {
                                $("#option3").hide(200);
                                $("#option3 input").removeClass("required");
                            }
    });
    $("#quote_numpages").change(
                        function(){
                            var selected = this.options[this.selectedIndex].text;
                            if(selected == "Other") {
                                $("#option4 input").addClass("required");
                                $("#option4").show(200);
                            } else {
                                $("#option4 input").removeClass("required");
                                $("#option4").hide(200);
                            }
    });
    $("#quote_finsize").change(
                        function(){
                            var selected = this.options[this.selectedIndex].text;
                            if(selected == "Other") {
                                $("#option5 input").addClass("required");
                                $("#option5").show(200);
                            } else {
                                $("#option5 input").removeClass("required");
                                $("#option5").hide(200);
                            }
    });
    $("#quote_reset").click(
                        function(){
                            for(var i=1;i<6;i++) {
                                $("#option"+i).hide(200);
                            }

    });

    $("p.link_code").hover(function() {
        $(this).addClass("link_code_hover");
        //css({ padding: "5px", background: "#DDD", color: "" });
    }, function() {
        $(this).removeClass("link_code_hover");
        //$(this).css({ padding: "5px", background: "#DDD", color: "" });
    });
});