// jquery-setup.min.js
// @author kamil@cfstudio.pl
// @copyright cfstudio@cfstudio.pl 2010.
$(document).ready(function(){
    var containerHeight = $(document).height();
    $('#bottom-bar').css('top',containerHeight-15);
    $('#metal-bottom-repeat').css('top',containerHeight-165);
    $('.top-menu-item').hover(function(){
        $(this).find('.left-corner-hide').removeClass().addClass('left-corner-show left-float');
        $(this).find('.top-menu-button-hide').removeClass().addClass('top-menu-button-show left-float uppercase');
        $(this).find('.right-corner-hide').removeClass().addClass('right-corner-show left-float');
    },function(){
        $(this).find('.left-corner-show').removeClass().addClass('left-corner-hide left-float');
        $(this).find('.top-menu-button-show').removeClass().addClass('top-menu-button-hide left-float uppercase');
        $(this).find('.right-corner-show').removeClass().addClass('right-corner-hide left-float');
    });
    $('.top-menu-item-active').find('.left-corner-hide').removeClass().addClass('left-corner-show left-float');
    $('.top-menu-item-active').find('.top-menu-button-hide').removeClass().addClass('top-menu-button-show left-float uppercase');
    $('.top-menu-item-active').find('.right-corner-hide').removeClass().addClass('right-corner-show left-float');
    
    $('.category-item-tab').prepend('<span></span>');
    $('.product-image-tab').prepend('<span></span>');
    $('.product-thumb-tab').prepend('<span></span>');
    
    $('#slider1').anythingSlider({
        width           : 958,
        height          : 172,
        resizeContents  : true,
        theme           : 'metallic',
        autoPlay        : true,
        buildArrows     : false,
        delay           : 5000,
        pauseOnHover    : false,
        clickSlideshow  : "click"
    });
    var gfxFn = {
        bodyShadow:function(){
            var height = $(document).height();
            var width = $(document).width();
            $('#body-shadow').css({'width':width,'height':height,'opacity':0.7});
            $('#body-shadow').fadeIn(300);
        },
        bodyMsg:function(msg){
            var pos = $('.contact-send').offset();
            var bMsg = '<div class="bMsg"style="display:none;position:absolute;z-index:1000;background-color:#cccccc;font-size:12px;padding:10px;text-align:justify;">';
            $(bMsg).appendTo('body');
            $('.bMsg').html(msg).css({'left':pos.left+300,'top':pos.top-100}).show();

        }
    };
    var clickFn = {
        hideShadow:function(){
            $('#body-shadow').click(function(){
                $('.bMsg').fadeOut().remove();
                $(this).fadeOut(300);
            });
        }
    };
    clickFn.hideShadow();
    var smallContactFn = {
      init:function(){
        $('#s-contact').submit(function(evt){
            var strData = $(this).serialize();
            evt.preventDefault();
            $.ajax({
                type: "POST",
                url: 'contact.php',
                data: strData,
                    success: function(msg){
                        gfxFn.bodyShadow();
                        gfxFn.bodyMsg(msg);
                }
            });
        });
      }
    };
    smallContactFn.init();
    $('.scroll-pane').jScrollPane();

    var menFn = {
        init:function(){
            $('#front-menu ul li a').fadeTo(0,0.6);
            $('#front-menu ul li a').hover(function(){
                $(this).stop(true,false).animate({
                    'margin-right':10,
                    'opacity':1,
                    'font-size':18
                },200);
            },function(){
                $(this).stop(true,false).animate({
                    'margin-right':0,
                    'opacity':0.6,
                    'font-size':16
                },200);
            });
        }
    }
    menFn.init();

    var productEvents = {
        productPopUp:function(){
            $('#prod-wrapper').click(function(){
                $(this).hide().find('img').remove();
            });
            $('.category-item-tab').click(function(){
                var img = $(this).find('div').text();
                var pos = $(this).offset();
                $('#prod-wrapper').wrapInner('<img src="'+img+'" width="300">');
                var pHeight = $('#prod-wrapper').height();
                var pWidth = $('#prod-wrapper').width();
                $('#prod-wrapper').css({'left':pos.left-(pWidth/2),'top':pos.top-(pHeight/2)});
                $('#prod-wrapper').show();
            });
        }
    };
    productEvents.productPopUp();

});
