$(document).ready(function() {

    //PRODUCT VIEWER-------------------------------------------------------------------

    /*$('.thumb_select').click(function(){
     var t = $('.thumb_select').index(this);
     $('.thumb_select').removeClass('thumb_selected')
     $('.thumb_select').eq(t).addClass('thumb_selected')
     $('.product_img_big').fadeOut();
     $('.product_img_big').eq(t).fadeIn();
     });*/

    //INIT DROPDOWN-------------------------------------------------------------------

    $("#drop_down_1").msDropDown({
        mainCSS: 'dd2'
    });
    $("#drop_down_2").msDropDown({
        mainCSS: 'dd2'
    });
    $("#drop_down_3").msDropDown({
        mainCSS: 'dd2'
    });

    //TABS SCRIPT-------------------------------------------------------------------

    $(function() {
        var tabContainers = $('div.tabs > div');
        tabContainers.hide().filter(':first').show();

        $('div.tabs ul.tabNavigation a').click(function() {
            tabContainers.hide();
            tabContainers.filter(this.hash).show();
            $('div.tabs ul.tabNavigation a').removeClass('tab_select');
            $(this).addClass('tab_select');
            return false;
        }).filter(':first').click();
    });

    //TOOLTIP SCRIPT-------------------------------------------------------------------
    initTooltips();

    //SEARCHBOX-------------------------------------------------------------------
    jQuery.fn.fadeToggle = function(speed, easing, callback) {
        return this.animate({opacity: 'toggle'}, speed, easing, callback);
    };

    $('.icon_3').attr('href', 'javascript:void(0);');

    $('.icon_3').bind('click', function(e) {
        $('#metanavigation .lang').toggle();
        $('#searchfield').fadeToggle('slow');
    });

    //SITEMAP SCRIPT-------------------------------------------------------------------
    var sitemapLink = '#footernavi .foot_link:eq(3)';

    $(sitemapLink).removeAttr('href');
    $(sitemapLink).bind('click', function(e) {
        if (!$('#sitemap_content').length) {
            $('#foot').prepend('<div id="sitemap" style="display:none;">...</div>');
            $('#sitemap').load('/fileadmin/schneiderpen/php/sitemap.php?closebutton=1&lang=' + lang);
        }

        $('.first').hide();
        $('.second').hide();
        $('.third').hide();
        $('.fourth').hide();

        $('#sitemap').fadeIn('fast', function(e) {
            $(document).bind('click', function(e) {
                closeSitemap();
            });
            
            $('#sitemap,' + sitemapLink).click(function(e) {
                e.stopPropagation();
            });
        });
    });


    //SWF-OBJECT-------------------------------------------------------------------

    var flashvars = {};
    var params = {
        wmode: "transparent"
    };
    var attributes = {};
    swfobject.embedSWF("assets/dummy_flash.swf", "flash", "1280", "305", "9.0.0", "assets/expressInstall.swf", flashvars, params, attributes);


    //FONT REPLACE-------------------------------------------------------------------
    //$('#flash_wrap .content p').wrapInner('<span style="padding-bottom: 2px;" />');

    Cufon.replace('.menu ', {
        fontFamily: 'Frutiger Next Pro 700',
        hover: true
    });

    Cufon.replace('.sub_menu ', {
        fontFamily: 'Frutiger Next Pro 300',
        hover: true
    });

    Cufon.replace('.lang', {
        fontFamily: 'Frutiger Next Pro 700',
        hover: true
    });

    Cufon.replace('.foot_teaser_headline', {
        fontFamily: 'Frutiger Next Pro 700',
        hover: true
    });

    Cufon.replace('.headline_bold', {
        fontFamily: 'Frutiger Next Pro 700',
        hover: true
    });

    Cufon.replace('.headline_light', {
        fontFamily: 'Frutiger Next Pro 300',
        hover: true
    });

    Cufon.replace('.nav_main_title', {
        fontFamily: 'Frutiger Next Pro 700',
        hover: true
    });

    Cufon.replace('#nonflash h1', {
        fontFamily: 'Frutiger Next Pro 700',
        hover: true
    });

    Cufon.replace('#flash_wrap .content>h1', {
        fontFamily: 'Frutiger Next Pro 300',
        hover: true
    });

    Cufon.replace('#flash_wrap .content h1 strong', {
        fontFamily: 'Frutiger Next Pro 700',
        hover: true
    });

    Cufon.replace('#nonflash>p', {
        fontFamily: 'Frutiger Next Pro 300',
        hover: true
    });

    Cufon.replace('#flash_wrap .content>p', {
        fontFamily: 'Frutiger Next Pro 300',
        hover: true
    });

    Cufon.replace('.headline_bold_pv', {
        fontFamily: 'Frutiger Next Pro 700',
        hover: true
    });

    Cufon.replace('.corporate_text', {
        fontFamily: 'Frutiger Next Pro 300',
        hover: true
    });


    //DISABLE_DOTTED LINES on links---------------------------------------------------------------

    $('a').bind("focus", function() {
        $(this).blur();
    })

    //ACCORDION SCRIPT-------------------------------------------------------------------

    jQuery('#accordion_1').accordion({
        header: 'div.title',
        active: false,
        alwaysOpen: false,
        animated: 'easeslide'
    });

    jQuery('#accordion_2').accordion({
        header: 'div.title',
        active: false,
        alwaysOpen: false,
        animated: 'easeslide'
    });


    //MADE IN GERMANY - DYNAMIC SHOWING/HIDEING-------------------------------------------------------------------
    getWidth();
    display_made();


    function getWidth() {
        var my_width = $('body').width();
        return my_width;
    }

    $(window).resize(function() {
        if ((getWidth()) > 1260) {
            $('#made').fadeIn();
        }
        else {
            $('#made').fadeOut();

        }
    });

    function display_made() {
        if ((getWidth()) > 1260) {
            $('#made').fadeIn('fast');
        }
        else {
            $('#made').fadeOut('fast');

        }
    }

    //browser fixes-------------------------------------------------------------------

    if (jQuery.browser.msie && jQuery.browser.version == 6) {

        $('#product_view').css({

            'margin-left': 0 + 'px'
        })
    }

});

function closeSitemap() {
    $('#sitemap').fadeOut('fast', function(e) {
        $('.first').show();
        $('.second').show();
        $('.third').show();
        $('.fourth').show();
    });
}

function initTooltips() {
    $(".tooltip-arrow-small[title]").tooltip({
        'tipClass': 'toolbox arrow-small',
        'effect': 'slide'
    });

    $(".tooltip-xsmall[title]").tooltip({
        'tipClass': 'toolbox xsmall'
    });

    $(".tooltip-arrow-xsmall[title]").tooltip({
        'tipClass': 'toolbox arrow-xsmall'
    });

    $(".tooltip-arrow-big[title]").tooltip({
        'tipClass': 'toolbox arrow-big',
        'effect': 'slide',
        'offset': [40,0],
        'delay': 5
    });

    $(".tooltip-next").tooltip({
        'effect': 'slide',
        'offset': [40,0],
        'delay': 5
    });
}

function CommerceConnector(ean, countrycode) {
    var url = 'http://www.schneiderpen.de/fileadmin/schneiderpen/php/CommerceConnector/CommerceConnector.php?action=popup&countrycode=' + lang + '&EANCODE=' + ean;
    var ccWindow = window.open(url, 'cc', 'width=800,height=600,left=20,top=20');

    ccWindow.focus();
}

//START OLD PENFINDER POPUP
function openpopup(mypage, myname, w, h, pos, infocus) {
    var ean = mypage.substring(mypage.indexOf('EANCODE=') + 8);
    CommerceConnector(ean);
}
//END OLD PENFINDER POPUP

//START INFOBOXEN PROFIL

//END INFOBOXEN PROFIL

