Shadowbox.init({skipSetup: true});
jQuery(document).ready(function(){
    //setup shadowbox
    
    active_button('#small_block'+flip_active_item);
    attach_next_button();
    jQuery('.brugo_flip_button').hover(
    function(){
        jQuery(this).addClass('brugo_flip_button_hover');
    },
    function(){
        jQuery(this).removeClass('brugo_flip_button_hover');
    }
    );
});
var temp_effect = 'scale';
function attach_next_button(){
    if(current_brugo_page == 'grid'){
        attachto = jQuery( "#brugo_product_"+flip_active_item );
        var apos = attachto.position();
        var aleft = apos.left;
        var atop = apos.top;
        var aheight = attachto.height();
        var awidth = attachto.width();
        jQuery('#brugo_container').append('<div id="brugo_flip_next" onclick="flip_next(\'n\');" class="brugo_flip_next brugo_flip_button" style=""></div>');
        jQuery('#brugo_container').append('<div id="brugo_flip_prev" onclick="flip_next(\'b\');" class="brugo_flip_prev brugo_flip_button" style=""></div>')

    }
}
function active_button(but_id){
    jQuery(but_id).css('border','2px solid red').css({'opacity':'0.5','filter':'alpha(opacity=50)'});
}
function other_button(but_id){
    jQuery(but_id).css('border','1px solid #888888').css({'opacity':'1','filter':'alpha(opacity=100)'});
}
function flip_book(show_id){
  var selectedEffect = 'fade';
//var selectedEffect = temp_effect;
			// most effect types need no options passed by default
			var options = {};
                        var timeing = 500;
			// some effects have required parameters
			if ( selectedEffect === "scale" ) {
				options = { percent: 0 };
			} 
                        if(selectedEffect==="pulsate"){
                            timeing = 500
                        }
                        other_button('#small_block'+flip_active_item);
                        active_button('#small_block'+show_id);
			// run the effect
                        //alert(selectedEffect);
                        jQuery( "#brugo_product_"+flip_active_item ).hide( selectedEffect, options, timeing,
                            function(){
                                
                                var selectedEffect = 'fade';
                                //alert(selectedEffect);
                                var options = {};
                                var timeing = 500;
                                if ( selectedEffect === "scale" ) {
				options = { percent: 100 };
                                } 
                                if(selectedEffect==="pulsate"){
                                    timeing = 500;
                                }
                                
                                jQuery( "#brugo_product_"+show_id ).show( selectedEffect, options, timeing);
                            }
                        );
                        
                        flip_active_item = parseInt(show_id);
    
}
function random_effect(){
    'blind', 'bounce','clip', 'drop',  'fold', 'puff', 'slide', 'scale', 'size', 'pulsate'
    var n = Math.floor(Math.random()*12);
    //alert(n);
    var returnme = 'blind';
    switch(n){
        case 1:
            returnme = 'clip';
            break;
        case 2:
            returnme = 'bounce';
            break;
        case 3:
            returnme = 'blind';
            break;
        case 4:
            returnme = 'drop';
        break;
        case 5:
            returnme = 'fade';
        break;
        case 6:
            returnme = 'fold';
        break;
        case 7:
            returnme = 'highlight';
        break;
        case 8:
            returnme = 'puff';
        break;
        case 9:
            returnme = 'pulsate';
        break;
        case 10:
            returnme='scale';
            break;
        case 11:
            returnme='slide';
            break;
        default:
            returnme = 'scale';
    }
    return returnme;
}
function flip_next(direction){
    flip_active_item
    printorder
    var previous_array_index;
    var next_array_index;
    var current_item = jQuery("#brugo_product_"+flip_active_item);
    var num_print_array = printorder.length;
    var current_array_num = jQuery.inArray(flip_active_item,printorder);
    next_array_index = current_array_num+1;
    previous_array_index = current_array_num-1;
    if(current_array_num==0){
        previous_array_index = num_print_array - 1;
    }
    if(current_array_num==num_print_array-1){
        next_array_index=0;
    }
    var prev_id = printorder[previous_array_index]
    var next_id = printorder[next_array_index]
    var next_item = jQuery("#brugo_product_"+next_id);
    var prev_item = jQuery("#brugo_product_"+prev_id);
    other_button('#small_block'+flip_active_item);
                        
    if(direction=='n'){
        active_button('#small_block'+next_id);
        current_item.hide("slide", {direction:'right'}, 500,function(){
            next_item.show("slide",{direction:'left'},500);
            flip_active_item = next_id;
        });
    }
    if(direction == 'b'){
        active_button('#small_block'+prev_id);
        current_item.hide("slide", {direction:'left'}, 500,function(){
            prev_item.show("slide",{direction:'right'},500);
            flip_active_item = prev_id;
        });
    }
    
}
function show_multibuy(){
    jQuery('.brugomore-views').hide();
    jQuery('.category-products').hide();
    jQuery('#multi_buy').show();
}
function hide_multibuy(){
    jQuery('#multi_buy').hide();
    jQuery('.brugomore-views').show();
    jQuery('.category-products').show();
    
}
function multi_cart_submit(){
    jQuery( "#loading_overlay" ).dialog({
			height: 160,
			modal: true
		});
    jQuery('.brugo_multi_quantity_box').each(function(){
        var theid = jQuery(this).attr('id');
        var thequantity = parseInt(jQuery(this).val());
        if(thequantity>0){
            var thelink = jQuery('#linker_'+theid).val();
            jQuery.ajax({
                async:false,
                type: 'POST',
                url: thelink,
                data: "qty="+thequantity
            });
        }
    });
    window.location.reload();
}
function show_shadowbox(c_url){
        Shadowbox.open({
        content:    c_url,
        player:     'swf',
        height:     445,
        width:      445
    });

}


