/*
CSS Browser Selector v0.4.0 (Nov 02, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

var Metalier = {};
Metalier.countryCodeURL = "";
Metalier.countryCodeGeo = "";
Metalier.init = function () {
    if (typeof (google) == "undefined") {
        google = {}
    }
    if (google.loader.ClientLocation == null) {
        google.loader.ClientLocation = WIPlocation
    }
    try{
      Metalier.countryCodeURL = $("meta[name=region]").attr("content");
      Metalier.countryCodeGeo = google.loader.ClientLocation.address.country_code.toLowerCase();
      if (Metalier.countryCodeGeo == "au") {
          $("body").empty()
      }

    }
    catch(err){
    }
    Metalier.setupCommonEvents();
    $("#newsletterMenu fieldset").each(function () {
        $("#signUpSubmit", this).click(function () {
            Metalier.newsletterSignup($("#newsletterSignUp").val());
            return false
        })
    });
    $("#featureCarousel").each(function () {
        $(this).carousel()
    });
//    $("#coatingTabs").each(function () {
//        $("h5 a", this).click(function () {
//            Metalier.toggleTopic($(this).parent().parent());
//            return false
//        });
//        $(".topicPanel:not(:first)", this).removeClass("open")
//    });
    $("#previewTypesList .previewCategory").each(function () {
        if (!$(this).hasClass("hasBeenInitialised")) {
            $(this).mouseenter(function () {
                $(this).addClass("mouseOver");
                $(".previewCategory").stop(true, true);
                $(".previewCategory:not(.mouseOver)").css({
                    opacity: 0.4
                });
                $(".prev, .next", this).css({
                    opacity: 0.2
                }).animate({
                    opacity: 1
                }, 300, "easeOutQuad")
            });
            $(this).mouseleave(function () {
                $(".previewCategory:not(.mouseOver)").fadeTo("easeOutQuad", 1);
                $(this).removeClass("mouseOver")
            });
            $(".thumbs", this).jCarouselLite({
                btnPrev: $(".prev", this),
                btnNext: $(".next", this),
                easing: "easeOutCubic",
                speed: 300,
                visible: 1,
                afterEnd: function (a) {
                    var b = $("a", a).attr("href");
                    var c = $(this).parent().parent().prev();
                    c.attr("href", b)
                }
            });
            $("a.frame", this).fancybox({
                margin: 0,
                padding: 0,
                overlayOpacity: 0.7,
                overlayColor: "#000000",
                width: 820,
                height: 550,
                type: "ajax",
                onComplete: function () {
                    Metalier.setupGallery()
                }
            });
            $(this).addClass("hasBeenInitialised")
        }
    });
    $("#galleryPage").each(function () {
        Metalier.setupGallery()
    });
    $("#layoutApplication").each(function () {
        var a = $("#region_" + Metalier.countryCodeGeo);
        if (a.length == 0) {
            a = $("#region_row")
        }
        if (a.hasClass("open") == false) {
            $(".topicPanel.open").removeClass("open");
            a.addClass("open")
        }
        $(".topicPanel h5 a", this).click(function () {
            var b = $(this).parent().parent();
            if (b.hasClass("open")) {
                $(".topicContent", b).slideUp({
                    duration: 600,
                    easing: "easeOutQuint"
                });
                b.removeClass("open")
            } else {
                $(".topicContent", b).slideDown({
                    duration: 400,
                    easing: "easeOutExpo"
                });
                b.addClass("open")
            }
            return false
        })
    });
    $("#layoutContact").each(function () {})
};
Metalier.preloadImages = function (b) {
    preloadedImage = new Image();
    var a = b.length;
    while (a--) {
        preloadedImage.src = b[a]
    }
};
Metalier.setupCommonEvents = function () {
    $("input").focus(function () {
        $(this).addClass("focus")
    });
    $("input").blur(function () {
        $(this).removeClass("focus")
    })

    $("input#newsletterSignUp").focus(function(){
      if( $(this).val() == 'your email address' ){
        $(this).val('');
      }
    }).blur(function(){
      if( $(this).val() == ''){
        $(this).val('your email address');
      }
    });
};
Metalier.toggleTopic = function (a) {
    if (a.hasClass("open")) {
        $(".topicContent", a).slideUp({
            duration: 600,
            easing: "easeOutQuint"
        });
        a.removeClass("open")
    } else {
        $(".topicContent", a).slideDown({
            duration: 400,
            easing: "easeOutExpo"
        });
        a.addClass("open")
    }
};
Metalier.setupGallery = function () {
    var a = $("li", ".thumbnails").index($(".thumbnails .selected"));
    $(".thumbnails").gallery({
        imageIndex: a
    })
};
Metalier.newsletterSignup = function (b) {
    var a = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
    if (a.test(b) === false) {
        $("#newsletterMenu label").addClass("error").html("Please enter a valid address...").hide().fadeIn({
            duration: 800,
            easing: "easeOutExpo"
        });
        return
    }
    $("#newsletterSignUpForm").submit()
};
$(document).ready(function () {
    Metalier.init()
});

