var $j = jQuery.noConflict();

$j(document).ready(function(){
    
    var lightbox = new Lightbox();

    $j("p#product-img a").hide();
    $j("p#product-img a#i1").show();

    $j("#imageContainer").append("<span></span>");

    /////////////////////////////////// product main img

    var img_height = $j("p#product-img a#i1 img").height();
    var add = (285 - img_height)/2;
    $j("p#product-img a#i1 img").css("top",add);
    $j("p#product-img a#i1").parent().children('.zoom-icon-link').css("top",15+add);
    $j("p#product-img a#i1").parent().children('.icon_new_single').css("top",10+add);
    $j("p#product-img a#i1").parent().children('.bargain_single').css("top",10+add);


    /////////////////////////////////////////////////////////////---------LEWE MENU

    ///schowaj wszystko na pierwszym poziomie
    $j(".col-left .nav-container #nav ul.level0").hide();
    ///schowaj wszystko na drugim poziomie
    $j(".col-left .nav-container #nav ul.level0 ul.level1").hide();


    $j('.col-left .nav-container #nav li').each(function(){

    if($j(this).children('ul.level0').length > 0)
        {
            $j(this).children("a").attr('href','#level0_0');
        }
        })

    /////////////rozwin active na stronie podkategorii

    if($j('#nav li').hasClass('active')){$j('#nav li.active ul.level0').show();}
   // if($j('#nav li.active ul.level0 li ul.level1 li').hasClass('active'))
    $j('#nav li.active ul.level0 li ul.level1').show();
        
    ///-------------------------------------------------------------------click

/*
    $j(".col-left .nav-container #nav li.level0 a").live('click', function(){

        $j(".col-left .nav-container #nav li").removeClass('clicked');
        $j(this).parent().addClass('clicked');

        $j(".col-left .nav-container #nav li").each(function(){

            if($j(this).hasClass('clicked') || $j(this).children('ul li').hasClass('clicked'))
            {
            }
            else
                {
                $j(this).children("ul.level0").slideUp(400);
                }
        });

        var isVisible = $j(this).parent().children('ul.level0').css('display');

        if(isVisible == 'none')
            $j(this).parent().children('ul.level0').stop(true,true).slideDown(400);

    });

    

    $j(".col-left .nav-container #nav ul.level0").live('mouseenter', function(){

        $j(this).show();

    });

    $j(".col-left .nav-container #nav ul.level0 .level1").live('mouseenter', function(){

        $j(this).show();

    });
*/

    $j(".col-left .nav-container #nav li.level-top a").live('click', function(){

       var isVisible =  $j(this).parent().children("ul.level0").css('display');

       if(isVisible == 'none')
          $j(this).parent().children("ul.level0").slideDown(400);
      else
          $j(this).parent().children("ul.level0").slideUp(400);

    });

    $j(".col-left .nav-container #nav li.level1 a").live('click', function(){

       var isVisible =  $j(this).parent().children("ul.level1").css('display');

       if(isVisible == 'none')
          $j(this).parent().children("ul.level1").slideDown(400);
      else
          $j(this).parent().children("ul.level1").slideUp(400);

    });



    /////////////////////////////////////////////////////////////---------GÓRNE MENU


    var pathname = window.location.pathname;
    
    
    if(pathname == '/')
        $j('.top_menu #nav li:nth-child(1)').addClass('active');
    
    if(pathname == '/twoj_wzor')
        $j('.top_menu #nav li:nth-child(2)').addClass('active');  
    
    if(pathname == '/o_nas')
        $j('.top_menu #nav li:nth-child(3)').addClass('active');
    
    if(pathname == '/dzieje_sie')
        $j('.top_menu #nav li:nth-child(4)').addClass('active');  
    
    if(pathname == '/freekasy/')
        $j('.top_menu #nav li:nth-child(5)').addClass('active');  
    
    if(pathname == '/kontakt')
        $j('.top_menu #nav li:nth-child(6)').addClass('active');     




     ////////////////////////////////////////////// - pozycjonowoanie miniaturek do srodka
                                                         //na stronie produktu
        
        $j('.more-views ul li').each(function(){

            var img_width = $j(this).children('a').children('img').width();
            var img_height = $j(this).children('a').children('img').height();

            if(img_width > 58)
                {
                  $j(this).children('a').children('img').css('left',((58-img_width)/2)
              );
                }

            if(img_height > 58)
                {
                  $j(this).children('a').children('img').css('top',((58-img_height)/2));
                }

        })


    ////////////////////////////////////////////////----------product view lightbox

    $j(".more-views li a").live('click', function(){


        var img_id = $j(this).attr('id');
        var img_index = img_id.substring(1);

        $j("p#product-img a").hide();
        $j("p#product-img a#i"+img_index).show();

    /////////////////////////////////// product main img

    var img_height = $j("p#product-img a#i"+img_index+" img").height();
    var add = (285 - img_height)/2;
    //console.log($j("p#product-img a#i"+img_index).parent().children('.icon_new_single'));
    $j("p#product-img a#i"+img_index+" img").css("top",add);
    $j("p#product-img a#i"+img_index).parent().children('.zoom-icon-link').css("top",15+add);
    $j("p#product-img a#i"+img_index).parent().children('.icon_new_single').css("top",10+add);
    $j("p#product-img a#i"+img_index).parent().children('.bargain_single').css("top",10+add);
    ///////////////////////////////////////////////////


    });


    $j(".product-img-box p a").live('click', function(){


        });

    ////////////////////////////////////////////lightbox logo - nie paca
    /*
$('#imageContainer #hoverNav a').live('click', function(){

    $('#imageContainer span').hide();
});
*/


    /////////////////////////////////////////// products list equal height

    var title_height = 0;

    $j('.category-products ul li.item').each(function(){


        var tmp_height = $j(this).children('.product-name').height();

        // alert(tmp_height);

        if(tmp_height > title_height)
        {
            title_height = tmp_height;
        }
       
    });

    $j('.category-products ul li.item').each(function(){

        $j(this).children('.product-name').height(title_height);

    });


    ////////////////////////////////////////// colors
    $j('.block-layered-nav .block-content ul li a.active').each( function() {
        $j(this).css('background-position',' 0px -24px');
    });

    $j('.block-layered-nav .block-content ul li a').live('mouseover',function(){

        var el_class = $j(this).attr('rel');
        $j(this).css('background-position','0px -24px');

    });

    $j('.block-layered-nav .block-content ul li a').live('mouseout',function(){

        var el_class = $j(this).attr('rel');
        if(!$j(this).hasClass('active'))
            {
            $j(this).css('background-position','0px 0px');
            }
    });

    ///////////////////////////////////////////////////////////////
    ////////////////////////////////////////////// ocena - gwiazdki
    
    $j('.ocena-box .star').live('mouseover', function () {
        $j(this).addClass('active');
        $j(this).prevUntil(".star-title").addClass('active');
        $j(this).nextAll().addClass("no-active");
    });
    
    $j('.ocena-box .star').live('mouseout', function () {
        $j('.ocena-box .star').removeClass('active');
        $j('.ocena-box .star').removeClass('no-active');
    })
    
    $j('.ocena-box .star').live('click', function () {
        var id_array = $j(this).attr('id').split("_");
        var id = id_array[1];
        $j('.ocena-box .star').removeClass('active-static');
        
        $j(this).addClass('active-static');
        $j(this).prevUntil(".star-title").addClass('active-static');
        $j("#Ocena_"+id).attr("checked", "checked");
    });

    /////////////////////////////////////////////////////////////////

   /////////////////////////////////////////////// Recenzje pokaż/ukryj

   $j('.form-add h2').live('click', function(){

        $j('.product-view #review-form ').show();
       
   })


    /////////**********************
    ///////// CSS
    ////////***********************


    //////////my account my data

    $j('#my-orders-table').parent().css('background','none');
    $j('#my-orders-table').parent().children('.pager').hide();
    $j('#my-orders-table').parent().children('.pager').first().show();
    $j('#my-orders-table').parent().children('.pager').first().children('.amount').hide();
    $j('#my-orders-table').parent().children('.pager').first().children('.limiter').css('padding-left','490px');
    $j('#my-reviews-table').parent().children('.pager').first().children('.limiter').css('padding-left','380px');
    $j('#my-orders-table').parent().children('.page-title').css('padding-left','0px');


    
    $j('#my-orders-table').parent().children('.buttons-set').hide();
    $j('#my-orders-table td').children('.nobr').children('.separator').hide();
    $j('#my-orders-table td').children('.nobr').children('a').first().css("background-image", "url('../../../skin/frontend/flyingcat/default/images/left-separator.png')");
    $j('#my-orders-table td').children('.nobr').children('a').first().css("background-repeat","repeat-x");
    $j('#my-orders-table td').children('.nobr').children('a').first().css("background-position","bottom left");

    //address book
    $j('.addresses-list').parent().children('.buttons-set').hide();
    $j('.addresses-additional .item .separator').hide();
    $j('.your-address-book').parent().parent().css('background','none');

    //order info
    $j('.order-info-header').parent().children('a').hide();
    $j('.order-info-header').parent().children('.separator').hide();
        //console.log( $j('.order-info-header').parent().parent().attr('class'));
    $j('.order-info-header').parent().parent().css('background','none');
    $j('.order-info-header').parent().parent().children('.title-buttons').hide();
    ////newsletter
    $j('.newsletter-title').parent().parent().css('padding', '10px 0px 40px 0px');
    $j('.newsletter-title').hide();
      ///////your comments
    $j('.your-comments-title').parent().parent().children('.pager').last().hide();
    $j('.your-comments-title').parent().parent().children('.pager').first().children('.amount').hide();
    $j('.your-comments-title').parent().parent().css('background','none');
    $j('.your-comments-title').parent().parent().children('.buttons-set').hide();
    $j('.your-comments-title').parent().css('margin','0px');
    $j('.your-comments-title').parent().css('paddingLeft','0px');
    $j('.your-comments-title').parent().parent().children('.pager').css('margin','0px 0px 0px 135px');
     /////// my wishlist
    $j('.my-wishlist').parent().css('background','none');
    $j('.my-wishlist').parent().children('.buttons-set').hide();
    $j('.my-wishlist').parent().css('margin','20px 0px 0px 25px');
    $j('.my-wishlist').parent().css('width','680px');
    ///////////////// my review details
    $j('.comm-details-header').parent().parent().parent().css('background','none');
    //////// share
    $j('.send-to-friends-h').parent().parent().css('padding-bottom','40px');
    $j('.send-to-friends-h').parent().parent().css('width','425px');


    //////// buttons

    $j('#review-form .button').live('mouseover', function(){

              $j(this).animate({
              opacity: 0.75
  }, 10, function() {
    // Animation complete.
  });
    })

    $j('#review-form .button').live('mouseout', function(){

              $j(this).animate({
              opacity: 1.0
  }, 10, function() {
    // Animation complete.
  });
    })


    $j('.my-account .button').live('mouseover', function(){

              $j(this).animate({
              opacity: 0.75
  }, 10, function() {
    // Animation complete.
  });
    })

    $j('.my-account .button').live('mouseout', function(){

              $j(this).animate({
              opacity: 1.0
  }, 10, function() {
    // Animation complete.
  });
    })


    $j('.contact-form button').live('mouseover', function(){

              $j(this).animate({
              opacity: 0.75
  }, 10, function() {
    // Animation complete.
  });
    })

    $j('.contact-form button').live('mouseout', function(){

              $j(this).animate({
              opacity: 1.0
  }, 10, function() {
    // Animation complete.
  });
    })

    $j('.addresses-primary ul li.item p a').live('mouseover', function(){

              $j(this).animate({
              opacity: 0.75
  }, 10, function() {
    // Animation complete.
  });
    })

    $j('.addresses-primary ul li.item p a').live('mouseout', function(){

              $j(this).animate({
              opacity: 1.0
  }, 10, function() {
    // Animation complete.
  });
    })

    $j('.addresses-additional ul li.item p a').live('mouseover', function(){

              $j(this).animate({
              opacity: 0.75
  }, 10, function() {
    // Animation complete.
  });
    })

    $j('.addresses-additional ul li.item p a').live('mouseout', function(){

              $j(this).animate({
              opacity: 1.0
  }, 10, function() {
    // Animation complete.
  });
    })

/////////////////////////////////////////////////////// CUSTOM PRICE LABEL

if($j('.custom-price-label').parent().children('.box-tags').children('.product-tags').length > 0)
{
    $j('.custom-price-label').css('bottom','69px');
}

var isVisible = $j('.custom-price-label').parent().children('.price-box').children('.old-price').css('display');
if( isVisible == 'block')
{
    $j('.custom-price-label').hide();
    $j('.custom-price-label').parent().children('.price-box').css('margin-left','0px');
}


//////////////////////////////////////////////////////// CART EQUAL COLUMNS

//alert('test');

var heights = new Array(); 
heights[0] = $j('.cart-collaterals .col2-set .col-2 #discount-coupon-form').height();
heights[1] = $j('.cart-collaterals .col2-set .col-2 .shipping').height();
heights[2] = $j('.cart-collaterals .totals').height();
var max_height = 0;

$j.each(heights, function(index, value) { 
  if(value > max_height)
      max_height = value;
});

$j('.cart-collaterals .col2-set .col-2 #discount-coupon-form').height(max_height);
$j('.cart-collaterals .col2-set .col-2 .shipping').height(max_height)
$j('.cart-collaterals .totals').height(max_height);

//alert('max_height:' + max_height);
////////////////

//$j('shopping-cart-totals-table tbody tr').eq(1).children('td').css('marginBottom','15px');


//CHECKOUT STEP 4
/*
$j('input#p_method_checkmo').live('click',function(){

    alert('test');
    $j('ul#payment_form_checkmo li label').hide();

});
*/
//CHECKOUT STEP 5



});




