 $(document).ready(function(){   
	$('#rotator').cycle({
        fx: 'fade',
        pager:  '#kropki',
        next:   '#arrow_right',
        prev:   '#arrow_left',
		timeout: 7000
    });
    if (!$('#mycarousel').has("li")) {
        $('#mycarousel').remove();
        $('div[class^="jcarousel"]').remove();
    }
    if (!($('#mycarousel li').html())){
        $('#mycarousel').remove();
        $('div[class^="jcarousel"]').remove();
        $('.product-info').css({
            'padding-top':'15px'
        });
    }
    if ( ($('#mycarousel').has("li")) || ($('#mycarousel li').html()) ){
        jQuery('#mycarousel').jcarousel({
            vertical: false,
            scroll: 1
        });
    }
});

function autoHeightAndWidthALL(obj,h,w){
    $(obj).each( function(){
        if($(this).height() > h && h > 0){
            $(this).height(h);
        }
        if($(this).width() > w && w > 0){
            $(this).width(w);
        }
    });
}

function autoHeightAndWidth(obj,h,w){
    if($(obj).height() > h && h > 0){
        $(obj).height(h);
    }
    if($(obj).width() > w && w > 0){
        $(obj).width(w);
    }
}

function relocateObj(objName,objDestination){
    var objMessage = $(objName);
    if(!objMessage != null){
        $(objName).each(function(){
            $(this).remove();
        });
        $(objDestination).append(objMessage);
        return true;
    }
    return false;
}

function addBorderDivs(objName,addPrefix,addClass){
    var udnefined;
    if ((addPrefix != udnefined) && (addClass != udnefined)){
        $(objName).each(function(){
            //alert('oba');
            $(this).wrap('<div class="'+addPrefix+'t '+addClass+'"><div class="'+addPrefix+'b '+addClass+'"><div class="'+addPrefix+'r '+addClass+'"><div class="'+addPrefix+'l '+addClass+'"><div class="'+addPrefix+'tl '+addClass+'"><div class="'+addPrefix+'tr '+addClass+'"><div class="'+addPrefix+'bl '+addClass+'"><div class="'+addPrefix+'br '+addClass+'"></div></div></div></div></div></div></div></div>');
        });
    }else if (addClass != udnefined){
        $(objName).each(function(){
            $(this).wrap('<div class="t '+addClass+'"><div class="b '+addClass+'"><div class="r '+addClass+'"><div class="l '+addClass+'"><div class="tl '+addClass+'"><div class="tr '+addClass+'"><div class="bl '+addClass+'"><div class="br '+addClass+'"></div></div></div></div></div></div></div></div>');
        });
    }else if (addPrefix != udnefined){
        $(objName).each(function(){
            $(this).wrap('<div class="'+addPrefix+'t"><div class="'+addPrefix+'b"><div class="'+addPrefix+'r"><div class="'+addPrefix+'l"><div class="'+addPrefix+'tl"><div class="'+addPrefix+'tr"><div class="'+addPrefix+'bl"><div class="'+addPrefix+'br"></div></div></div></div></div></div></div></div>');
        });
    }else{
        $(objName).each(function(){
            $(this).wrap('<div class="t"><div class="b"><div class="r"><div class="l"><div class="tl"><div class="tr"><div class="bl"><div class="br"></div></div></div></div></div></div></div></div>');
        });
    }
}

function addLeftAndRightDiv(objName,addPrefix,addClass) {
    var udnefined;
    if ((addPrefix != udnefined) && (addClass != udnefined)){
        $(objName).each(function(){
            //alert('oba');
            $(this).wrap('<div class="'+addPrefix+'l '+addClass+'"><div class="'+addPrefix+'r '+addClass+'"></div></div>');
        });
    }else if (addClass != udnefined){
        $(objName).each(function(){
            $(this).wrap('<div class="l '+addClass+'"><div class="r '+addClass+'"></div></div>');
        });
    }else if (addPrefix != udnefined){
        $(objName).each(function(){
            $(this).wrap('<div class="'+addPrefix+'l"><div class="'+addPrefix+'r"></div></div>');
        });
    }else{
        $(objName).each(function(){
            $(this).wrap('<div class="l"><div class="r"></div></div>');
        });
    }
}
function addLeftAndCenterDiv(objName,addPrefix,addClass) {
    var udnefined;
    if ((addPrefix != udnefined) && (addClass != udnefined)){
        $(objName).each(function(){
            //alert('oba');
            $(this).wrap('<div class="'+addPrefix+'c '+addClass+'"><div class="'+addPrefix+'l '+addClass+'"></div></div>');
        });
    }else if (addClass != udnefined){
        $(objName).each(function(){
            $(this).wrap('<div class="c '+addClass+'"><div class="l '+addClass+'"></div></div>');
        });
    }else if (addPrefix != udnefined){
        $(objName).each(function(){
            $(this).wrap('<div class="'+addPrefix+'c"><div class="'+addPrefix+'l"></div></div>');
        });
    }else{
        $(objName).each(function(){
            $(this).wrap('<div class="c"><div class="l"></div></div>');
        });
    }
}
function addTopAndBottomDiv(objName,addPrefix,addClass) {
    var udnefined;
    if ((addPrefix != udnefined) && (addClass != udnefined)){
        $(objName).each(function(){
            //alert('oba');
            $(this).wrap('<div class="'+addPrefix+'t '+addClass+'"><div class="'+addPrefix+'b '+addClass+'"></div></div>');
        });
    }else if (addClass != udnefined){
        $(objName).each(function(){
            $(this).wrap('<div class="t '+addClass+'"><div class="b '+addClass+'"></div></div>');
        });
    }else if (addPrefix != udnefined){
        $(objName).each(function(){
            $(this).wrap('<div class="'+addPrefix+'t"><div class="'+addPrefix+'b"></div></div>');
        });
    }else{
        $(objName).each(function(){
            $(this).wrap('<div class="t"><div class="b"></div></div>');
        });
    }
}

function backgroundFix(strObj,numBackgroundPositionX,numBaseBodyWidth,numStop){ 
    var numBodyWidth = $(strObj).width();
    if(numStop == undefined){
        numStop = 0;
    }
    if(((strObj != undefined) && (numBackgroundPositionX != undefined) && (numBaseBodyWidth != undefined)) && numBodyWidth > numStop){
        if(((numBodyWidth % 2) != 0) && ($.browser.mozilla)){
            numBodyWidth--;
        }
  
        if(numBodyWidth > numBaseBodyWidth){
            numBodyWidth -= numBaseBodyWidth;
            numBodyWidth /= 2;
            numBackgroundPositionX += numBodyWidth;
        }else if(numBodyWidth < numBaseBodyWidth){
            numBodyWidth = numBaseBodyWidth - numBodyWidth;
            numBodyWidth /= 2;
            numBackgroundPositionX -= numBodyWidth;
        }
        if(!($.browser.mozilla)){
            numBackgroundPositionX--;
        }
        if($.browser.msie){
            numBackgroundPositionX = parseInt(numBackgroundPositionX);
        }
  
        $(strObj).css({
            'background-position':numBackgroundPositionX +'px 0'
        });
        return true;
    }else{
        return false;
    }
}


function verticalMenuFix(strContainer,strMain,strSubs){
    if($(strMain).html() != undefined){
        var numIndex = 0;
        //	       $('body').append('<div id="debug"/>');
        $(strMain).each(function(){
            $(this).addClass('id-' + numIndex).append('<ul class="submenu" id="submenu-'+numIndex+'"></ul>');
            tmp = '<ul class="submenu" id="submenu-'+numIndex+'"></ul>';
            //	           $('#debug').append($(this).html());
            numIndex++;
        });
        numIndex = 0;
        $(strContainer+' li').each(function(){
            if($(this).hasClass(strSubs.replace('.',''))){
                $(strMain+'.id-' + numIndex + ' ul').append($(this));
            }else
            if($(this).hasClass(strMain.replace('.',''))){
                if($(this).hasClass('id-' + numIndex)){
                }else{
                    numIndex++;
                }
            }
        });
        numIndex = undefined;
    }
}

function equalHeights(strObj){

    if(!$(strObj).hasClass('list_Products_Also')){
        var numHeight = 0;
        $(strObj).each(function(){
            if($(this).height() > numHeight){
                numHeight = $(this).height();
            }
        });
        $(strObj).each(function(){
            $(strObj).height(numHeight);
        });
    }
}

$(document).ready(function(){
    if($('#johnny').html() != undefined){
        $('#johnny').css('display','block').appendTo('.contentbox .content');
    }
    window.onload = function(){
        equalHeights('#lcontent_center .cproduct_title a');
        equalHeights('#lcontent_center .cproduct_title');
      /*  equalHeights('#lcontent_center .productListItem .cprod_bg');
        $('#lcontent_center .productListItem .cprod_bg .cprod_table').each(function(){
            $(this).height($('#lcontent_center .productListItem .cprod_bg').height());
            $(this).children().children().height($('#lcontent_center .productListItem .cprod_bg').height());
        
        });
        $('#lcontent_center .productListItem .cprod_bg').each(function(){
            $(this).removeAttr('style');
        });
        equalHeights('#lcontent_center .productListItem .cprod_bg');
        equalHeights('#lcontent_center .productListItem'); */
        equalHeights('.show.categories');
        equalHeights('.show.categories h2');
        if(($.browser.msie) && (($.browser.version == '8.0'))){
        var $imgInListProductsAlso = $('.list_Products_Also div.cfoto2_bg img');
//        var $imgIncFotosmin = $('#strona_produktu div.cfotosmin img');
//            if($imgIncFotosmin.width() >= 51){
//                $imgIncFotosmin.width(51);
//            }
//            if($imgIncFotosmin.height() >= 48){
//                $imgIncFotosmin.height(48);
//            }
//            $imgInListProductsAlso.width() > 134 ? $imgInListProductsAlso.width(135) : $imgInListProductsAlso.width();
//            $imgInListProductsAlso.height() > 91 ? $imgInListProductsAlso.height(92) : $imgInListProductsAlso.height();
            $imgInListProductsAlso.each(function(){
                $(this).css({'max-height':'91px','max-width':'1340px'});
            if($(this).width() > 134){
                $(this).width(135);
            }
            });
            var $imgIncFotosmin = $('#strona_produktu div.cfotosmin img');
            $imgIncFotosmin.width() > 50 ? $imgIncFotosmin.width(51) : $imgIncFotosmin.width();
            $imgIncFotosmin.height() > 47 ? $imgIncFotosmin.height(48) : $imgIncFotosmin.height();
        }
    }
    $('div.cfull_foto_bg').height($('div.cfull_foto_bg').parent().height());

    /* skrypt działa przy mnej więcej takiej strukturze

<div id="lfoot">
	<table id="footer_table">
		<tr>
			<td>
				<li><a href=""></a></li>
				<li><a href=""></a></li>
				<li><a href=""></a></li>
			</td>
		</tr>
	</table>
</div>
*****/

    var arAnchors = new Array();
    var arTmp = new Array();
    $('#footer_table td').each(function(){
        arAnchors.push($(this).html());
    });
    $('#footer_table').remove();
    var j = 1;
    for (i = 0; i < arAnchors.length; i++) {
        if(arAnchors[i] != '&nbsp;'){
            arTmp.push(arAnchors[i]);
        }
    }
    delete arAnchors;
    arAnchors = new Array();
    arAnchors = arTmp;
    for (i = 0; i < arAnchors.length; i++) {
        if((i % 3) == 0){
            $('#lfoot .lfoot_lists').append('<div class="lfoot_list" id="lfoot_list'+j+'"/>');
            $('#lfoot_list'+j).append('<ul class="cfoot_list" />');
            j++;
        }
        $('#lfoot_list'+(j-1)+' .cfoot_list').append('<li class="id-'+i+'"><span>&raquo;&nbsp;</span>'+arAnchors[i]+'</li>');
    }
    $('input').removeAttr('onblur');
    $('textarea').removeAttr('onblur');

    if(($('#lcontent .contentbox .content').html() != undefined) && ($('#lcontent .contentbox .content').height() < 175)){
        $('#lcontent .contentbox .content').height(175);
    }
    if(($('#lcontent .contentboxMainSite .content').html() != undefined) && ($('#lcontent .contentboxMainSite .content').height() < 175)){
        $('#lcontent .contentboxMainSite .content').height(175);
    }

    $('#SelectProductSort').wrap('<div class="SelectProductSort"><div class="c"><div class="l"><div class="r"></div></div></div></div>');
    var strNBSP = "&nbsp;";
    var numPrice = 0;
    if($('.menBox01').html() != undefined){
        var strHTML = $('.menBox01').html();
        $('.menBox01').html('');
        $('.menBox01').append('<div class="content2" />');
        $('.menBox01 .content2').html(strHTML);
        addBorderDivs('.menBox01 .content2');
        $('.menBox01').appendTo('.contentboxMainSite .content');
    }
    if($('.menBox02').html() != undefined){
        $('.menBox02').appendTo('.contentboxMainSite .search');
    }
    $('#lbg').snowfall({flakeCount : 100, maxSpeed : 10});
});
