$(document).ready(function(){
    initClearInput();
    initSlideToggle();
    initFade();
    //initCenter();
    initShare();
    initMap();
    initInspire();
    initSizeGuide();
    initAboutToggle();
    initContactUs();

    //Detect the browser
    var $copy = $('div.SPA_printcontact').clone();
    var $body = $('body');

    $copy.insertAfter('#printdate');

    if($.browser.msie) {
        $body.addClass('msie')
        var userAgent = userAgent.substring(0,userAgent.indexOf('.'));
        var version =  $.browser.version.replace(".0","");
        $body.addClass('msie' + version)
    }
    if($.browser.webkit) {
        $body.addClass('webkit')
    }
    if($.browser.mozilla) {
        $body.addClass('mozilla')
    }
});

$(window).load(function(){
    initCenter();
});


function initClearInput(){
    $('input[type=text]').focus(function(){
        var oldValue = this.value;
        this.value = '';
        $(this).focusout(function(){
            if (this.value == ''){
                this.value = oldValue;
            }
        });
    });
}

function initSlideToggle(){
    $('.product_desc').find('.trigger').click(function() {
        $('.product_desc').find('.active').each(function(){
            $(this).parents('.product_desc').find('.product_content').animate({opacity:'toggle', height: 'toggle'}, 200);//slideToggle(200);
            $(this).toggleClass("active");
        })
        $(this).parents('.product_desc').find('.product_content').animate({opacity:'toggle', height: 'toggle'}, 200);//slideToggle(200);
        $(this).toggleClass("active");
        return false;
    });
}

function initFade(){
    $("#thumbstrip > ul > li > a").click(function(e){
//    e.preventDefault();
        $("#thumbstrip > ul > li > a").addClass("active").not(this).removeClass("active");
    });
}


function initCenter(){
    $('.center').each(function(){
        var width = $(this).outerWidth();
        var parentWidth = $(this).parent().width();
        var left = (parentWidth - width) / 2;
        $(this).css('margin-left',left);
    });
}

function initShare(){
    $('a.colorbox_share').colorbox({scrolling: true, fastIframe: false, iframe:true, width:800, height:950});
}


function initMap(){
    $('a.colorbox_map').colorbox({scrolling: false, fastIframe: false, iframe:true, width:800, height:900});
}

function initInspire(){
    $('a.colorbox_inspire').colorbox({width:900,height:950,inline:true,scrolling: false,href:"#inline_colorbox"});
}

function initSizeGuide(){
    $('a.size_guide').colorbox({scrolling: false, fastIframe: false, iframe:true, width:820, height:900});
    $('a.m2m').colorbox({scrolling: false, fastIframe: false, iframe:true, width:820, height:900});
    $('a.view_price').colorbox({scrolling: true, fastIframe: false, iframe:true, width:800, height:800});
}

function initContactUs(){
    $('a.contact_us').colorbox({scrolling: true, fastIframe: false, iframe:true, width:780, height:822});
}

function initAboutToggle(){
    $('#slideshow_dropdown').find('.trigger').click(function() {
        $(this).parents('#slideshow_dropdown').find('.slideshow_list').animate({opacity:'toggle', height: 'toggle'}, 200);//slideToggle(200);
        $(this).toggleClass("active");
        return false;
    });
}
