/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 06.10.11
 * Time: 14:40
 * To change this template use File | Settings | File Templates.
 */
var iv;
$(document).ready(function(){

    slider('slogan',true);

//    $('.slideritem').css('width',$(document).width());
   // $('.sliderpager').css('position','relative');

    $('a','.sliderpager').html('') ;

    if ($('#details').length > 0) {
        $('img','#details').mouseleave(function(){
            $('.plus').show();
        });
        $('img','#details').mouseenter(function(){
            $('.plus').hide('slow');
        });
    }



});
function slider(id, pagin){
    if ($("#"+id).length > 0) {
        $("#"+id).slides({
            randomize: true,
            play: 7000,
            effect: 'fade',
            generatePagination: pagin,
            pagination: pagin,
            paginationClass: 'sliderpager',
            animationComplete: function(){
                changeBGimg(id);
            }
        });
        changeBGimg(id);
    }
}

function changeBGimg(container){
   href = $('.item:visible .img_tag','#'+container).attr('href');
   $('.item:visible .slideritem:visible','#'+container).css('background','url("'+href+'") no-repeat top center');
}

function showDetailsImg(img_src){
    iv = $('#details').iviewer({
        src: img_src,
        ui_disabled: true,
        zoom_delta: delta,
        update_on_resize: false,
        onMouseMove: function(coords) { },
        onStartDrag: function(coords) { return false; }, //this image will not be dragged
        onDrag: function(coords) { },
        onClick: function(){
            if ($('.zoomin').length > 0) {
                iv.iviewer('zoom_by', -1);
                $('.productimage').removeClass('zoomin');
                $('img','#details').css('cursor','-moz-zoom-in');
            } else {
                $('.productimage').addClass('zoomin');
                iv.iviewer('zoom_by', 1);
                $('img','#details').css('cursor','-moz-zoom-out');
            }

        }
    });
}

function showAboutContent(div_id){
    if (div_id.substr(0,15) == 'why_pragga_menu') {
        $('.why_pragga_menu').hide();
        $('#'+div_id).fadeIn();
        $('.active', '#accordeon').removeClass('active');
        $('#a_'+div_id).addClass('active');
    } else {
        $('#why_pragga, #history, #legal').hide();
        $('.why_pragga_menu').hide();
        $('#'+div_id).fadeIn();
        if (div_id == 'why_pragga') {
            showAboutContent('why_pragga_menu_1');
        }
    }
    Cufon.replace('.topmenu a, div.title, h1, h2, h3, .leftmenu a, .cifer, .month, .cufoned', {
            hover: true
    });
}

function switchPage(contr,page,option) {
    if (option == undefined) {
        opt = '';
    } else {
        opt = option;
    }
    $.getJSON(url+contr+'/?action=get'+opt,{page:page-1}, function(data) {
        if(data.success){
            $('#data_container').html(data.tpl);
        }
    });
}
function showPopup(url) {
    $('body').animate({
            scrollTop: true
        },
        500,
        function(){}
    );
    hidePopup();
    $('#popup .popup_image').attr('src', url);
}
function loadPopup(img) {
    var windowWidth    = $(window).width();
    var windowHeight   = $(window).height();
    var documentWidth  = $(document).width();
    var documentHeight = $(document).height();
    var width  = 970;
    var height = 470;
    var left  = (windowWidth / 2) - ((width+34) / 2);
    var top   = 80;
    if (left < 0) {
        left = 0;
    }
    $('#popup').css('width', ''+width+'px').css('left', ''+left+'px').css('top', ''+top+'px').show();

    $('#popup_bg').css('width', documentWidth+'px').css('height', documentHeight+'px').show().bind("click", function() {
        hidePopup();
    });
    $(window).bind('resize', function(s) {
        var windowWidth  = $(window).width();
        var windowHeight = $(window).height();
        var documentWidth  = $(document).width();
        var documentHeight = $(document).height();
        var left  = (windowWidth / 2) - ((width+34) / 2);
        if (left < 0) {
            left = 0;
        }
        $('#popup').css('left', ''+left+'px').show();
        $('#popup_bg').css('width', documentWidth+'px').css('height', documentHeight+'px');
    });
}
function hidePopup() {
    $('#popup').hide();
    $('#popup_bg').hide().unbind('click');
    $('#popup .popup_image').attr('src', '');
    $(window).unbind('resize');
}


