/*
* 2007-2011 PrestaShop 
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <contact@prestashop.com>
*  @copyright  2007-2011 PrestaShop SA
*  @version  Release: $Revision: 1.4 $
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

function pc_serialScrollFixLock(event, targeted, scrolled, items, position)
{
	var leftArrow = position == 0 ? true : false;
	var rightArrow = position + 5 >= $('#productscategory_list li:visible').length ? true : false;
	
	$('a#productscategory_scroll_left').css('cursor', leftArrow ? 'default' : 'pointer').fadeTo(0, leftArrow ? 0 : 1);		
	$('a#productscategory_scroll_right').css('cursor', rightArrow ? 'default' : 'pointer').fadeTo(0, rightArrow ? 0 : 1).css('display', rightArrow ? 'none' : 'block');

	return true;
}

$(document).ready(function()
{
$('.ajax_add_to_cart_button').removeAttr("href");
$('.ajax_add_to_cart_button').unbind("click");
	$(".fromVariation").live('click',function(){
        //var quantity = $(this).parent().parent().find(".cart_quantity_input").val();
		
        if($(this).hasClass('exclusive')){
            var quantity = $(this).parent().siblings().find(".cart_quantity_input").val();
        }else{
            var quantity = $(this).siblings().find(".cart_quantity_input").val();
        }
		var temp = $(this).attr('id').substring(1);
		var splitted = temp.split("_",2);
		var productId = splitted[1];
		var combinationId = splitted[0];
		ajaxCart.add(productId,combinationId,false,$(this),quantity,false);
		$(this).parent().parent().parent().parent().parent().children().animate({opacity: 0.10},750,
			function(){
				$(this).animate({opacity: 1},750);
			});
		
	});
	$('#productscategory_list').serialScroll({
		items: 'li',
		prev: 'a#productscategory_scroll_left',
		next: 'a#productscategory_scroll_right',
		axis: 'x',
		offset: 0,
		stop: true,
		onBefore: pc_serialScrollFixLock,
		duration: 300,
		step: 1,
		lazy: true,
		lock: false,
		force: false,
		cycle: false });
        
        $(".fancybox").fancybox({
            width: 900,
            height:900,
            href: '/eshop/getCombinations.php?' + "id_product=",
           titleShow: false,
            onStart: function(selectedArray, selectedIndex, selectedOpts){
                this.href = this.href + $(selectedArray).attr("rel").substring(16);
            },
            onComplete:function(){
                $("#fancybox-content div").css("overflow-x","hidden");
            } 
        });
        $("#closeProductMore").live("click",function(){
          $.fancybox.close();  
        });
        $(window).scroll(function(event){
            var columnsOffset = $("#columns").offset();
            var columnsHeight = $("#columns").height();
            var leftColumnBottom = $("#left_column").offset().top +  $("#left_column").height();
            var  centerColumnBottom = $("#center_column").offset().top +  $("#center_column").height();
            if($(this).scrollTop() > $("#columns").offset().top ){
                if(centerColumnBottom - leftColumnBottom <= 0){
                    //Si los offset inferiores de la columna de la derecha y la columna central difieren: 
                    if($("#left_column").offset().top > $(this).scrollTop()){
                        //Si la comuna derecha no esta alineada con el scroll. Lo crregimos
                          $("#left_column").css("top","0px");
                          $("#left_column").css("position","fixed");
                    }else{
                        //Si Las columnas no coinciden en la parte inferior re calculamos la posicion y la ponemos en relative para que calse en la parte inferior
                    var pos = columnsHeight - $("#left_column").height();
                     $("#left_column").css("position","relative");
                     $("#left_column").css("top",pos + "px");
                    }
                 }else{
                     // Todos los otros casos significan que estamos scrolleando:
                     $("#left_column").css("position","fixed");
                     $("#center_column").css("float","right");
                     $("#center_column").css("margin-right","10px");
                     $("#left_column").css("top","0px");
                 }
            } 
            else{
                //En posicion de reposo, el Scroll esta arriba de todo
                $("#left_column").css("position","relative");
            }
            
        });
        /*
		$('.addDefault').qtip({
			content : {
				url: '/eshop/getCombinations.php',
				data: {
					id_product : 0
				},
			},
			position: {
				adjust:{
					screen: true
				},
				corner:{
					target: "bottomLeft"
				}
			},
			api: {
				beforeContentUpdate: function(){
					$('.qtip').hide();
					this.options.content.data = {
						id_product: $(this.elements.target).attr("rel").substring(16)
					}
				}
			},
			style : {
				width: {
					max: 1000,
					min: 460
				},
				border: {
					radius: 2
				}
			},
			show: 'click',
			hide: 'focusout'
		});
        */
});
