$(document).ready(function(){
    $("a.fancy").fancybox({
        'titleShow' : false,
        'transitionIn' : 'elastic',
        'transitionOut' : 'elastic',
        'easingIn' : 'easeOutBack',
        'easingOut' : 'easeInBack',
        'scrolling' : 'no'
    });

    /*$().jSnow({
     vSize: '500',
     fadeAway: true,
     flakes: 5,
     zIndex: 2
   });*/

    $("a.cluetip").cluetip({
        arrows: true,
        cluetipClass: 'jtip'
    });

    if ( ( jQuery.browser.webkit || jQuery.browser.opera ) && document.readyState != "complete"){
        setTimeout( arguments.callee, 100 );
        return;
    }

    /*$.resizeAdaptive();*/
    $.resizeAdaptiveImages();
    /*$.resizeAssocs();

    $(window).bind( "resize", function(){
        $.resizeAdaptive();
        $.resizeAssocs();
    });*/

    $.insertFlash();

    $.startMenu();

});

$.startMenu = function(){
    $("li.dropper").mouseover(function(){
        $(this).find("ul.dropdown, div.dropdown-border").show();
    }).mouseout(function(){
        $(this).find("ul.dropdown, div.dropdown-border").hide();
    });
}

$.resizeAssocs = function(){


    var width = parseInt( $("div.view-port").css("width") ) - 250;

    if($("div.adaptive-assoc").length > 1){
        var new_width = ( width / 2 ) - 30 + "px" ;

        if( new_width < 350 ){
            new_width = width - 30 + "px";
        }

        $("div.adaptive-assoc").css("width", new_width );

        var icount = Math.floor( new_width / 120 );

        var inew_width = ( ( new_width * (100/icount) / 100 ) - 21 ) + "px" ;
        $("div.adaptive-assoc ul li:not(.header)").css("width", inew_width );
    }else{
        $("div.adaptive-assoc").css("width", width - 30 );
    }

}

$.resizeAdaptive = function(){
    var width = parseInt( $(".adaptive").css("width") );
    var count = Math.floor( width / 160 );

    if($(".adaptive .item").length <= count && parseInt($(".adaptive .item").length) > 3 ){
        count = parseInt($(".adaptive .item").length);
    }

    var new_width = ( width / count - 10 ) + "px" ;
    $(".adaptive .item").css("width", new_width );
}

$.resizeAdaptiveImages = function(){
    /*$(".item .photo a, ul.list li a, div.product div.description .picture a, .photo a").each(function(){
        var height = 120;
        var img_height = parseInt( $(this).find("img.image-pic").css("height") );
        if( height > img_height ){
            var padding = ( height - img_height ) / 2 ;
            $(this).css("padding-top",padding).css("height",height-padding);
        }
    });
    $("a.mini").each(function(){
        var height = 150;
        var img_height = parseInt( $(this).find("img").css("height") );
        if( height > img_height ){
            var padding = ( height - img_height ) / 2 ;
            $(this).css("padding-top",padding).css("height",height-padding);
        }
    });*/
}



$.message = function(message, type, options) {
    
    var html = "";
    if(type == "error"){
        html = "<p class='message-error'>"+message+"</p>";
    }else{
        html = "<p class='message-success'>"+message+"</p>";
    }

    var opts = {
        'content': html
    };

    opts = $.extend(opts, options);

    $.fancybox(opts);
}

$.insertFlash = function(){
    <!-- For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. -->
    var swfVersionStr = "0.0.0";
    <!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->
    var xiSwfUrlStr = "/flash/playerProductInstall.swf";
    var flashvars = {};
    flashvars.settingsXML = "/flash/rotator/settings.xml";
    var params = {};
    params.scale = "noscale";
    params.salign = "tl";
    params.wmode = "opaque";
    params.allowfullscreen = "true";
    params.allowscriptaccess = "sameDomain";
    var attributes = {};
    swfobject.embedSWF(
        "/flash/rotator/banner.swf?" + new Date().getTime(), "banner",
        "665", "178",
        swfVersionStr, xiSwfUrlStr,
        flashvars, params, attributes);
}
