var myhost='http://'+location.host+'/'
 
function importcsv(filename,totalrows,startnum,stringnum)
   {
       percentage=0;
       endi=Math.ceil(totalrows/stringnum);
       //alert(endi);
       onepart=100/endi;
       $("#load_percent").text("Импортировано: 0%");
       for(i=0;i<endi;i++)
       {
          // alert(myhost+"shop/import_csv/"+filename+"/"+(startnum+(stringnum*i)));

           $.getJSON(myhost+"shop/import_csv/"+filename+"/"+(startnum+(stringnum*i)),'',function(data){
                percentage+=onepart;
                //alert(data.addpercent);
                $("#load_percent").text("Импортировано: "+percentage.toFixed(2)+"%");
             });
          // $("#load_percent").load(myhost+"/import/import_csv/1/"+(startnum+(stringnum*i)));
       }

   }
   
$(document).ready(function(){

	$('#calend_main ul').height( $('#forum_main ul').height()-10 );

    $("a.zoom").fancybox();
	//$(".media_thumb li a img").mouseover(function(){
	//	$text = jQuery('<div class="img_desc"><div>'+$(this).attr('alt')+'</div></div>').bind("mouseout ", function(){ $(this).fadeOut(400, function(){$(this).remove()} ) } );
	//	$(this).parent().append($text).find('.img_desc').fadeTo(200, 0.7);
    //});
    
    // Заранее создаются div с описанием из alt
    imgs = $(".media_thumb li a img");
   // $text = jQuery('');
    //imgs.parent().append($text);
    
    // Отображаются и скрываются при наведении
    imgs.mouseenter(function(){
        $('#imagediv'+$(this).attr('id')).fadeTo(400, 0.8);
    });
    $(".img_desc").mouseleave(function(){
        $(this).hide();
    });
 
 
    currentHeight = $("#ct").height();
    $("#ct_foto, #ct_video").height(currentHeight);
    
    $("#stars a").tipsy();
	
	$(".tag").corner("top");
	//$(".checklist div div").corner();
    
    $(".media_list li:even").css("background-color", "#1a1a1a");
    $(".media_list li:odd").css("background-color", "#0d0d0d");
/*
    var angle = 0;
    setInterval(function() { angle+=180; $('.icon').rotateAnimation(angle);}, 6000);

    $('#image3').rotate({maxAngle:0,minAngle:360,
	    bind:
	    [
	        {"mouseover":function(){$(this).rotateAnimation(85);}},
	        {"mouseout":function(){$(this).rotateAnimation(-35);}}
	    ]
	});
*/
    setInterval(
        function () {
            $('#logo').animate({rotate: '+=10deg'}, 0);
        },
        200
    );

    var shop_count_act = 0;
    setInterval(
      function(){
        if( shop_count_act == 0)
        {
         $('.shop_count').css('color','red');
         shop_count_act = 1;
        }
        if( shop_count_act == 1)
        {
         $('.shop_count').css('color','#ffe880');
         shop_count_act = 0;
        }
      }, 500
      );
	
	
     $("#somebutton").click(
        function () {
        alert("Начало импорта. Не перезагружайте страницу, пока импорт не завершится на 100%");
        $("#somebutton").attr({ "disabled":"disabled" });
            importcsv($("#filename").val(),$("#filestr").val(),1,10);     });
			
	 $("#uppercat").change(
        function (){
            $("#catid").attr({ "disabled":"disabled" });
            $("#catid").load(myhost+"shop/loadsubcats/"+$("#uppercat").val(),'',function(){
            $("#catid").attr({ "disabled":"" });});
        });
		
		$("#typelink").click(
        function () {
			$(this).addClass('active'); 
			$('#cat_menu').show(); 
			$('#man_menu').hide(); 
			$("#vendorlink").removeClass('active'); 
			return false;
		});
		$("#vendorlink").click(
        function () {
			$(this).addClass('active'); 
			$('#man_menu').show(); 
			$('#cat_menu').hide(); 
			$("#typelink").removeClass('active'); 
			return false;
		});

    //$('#forum_main li:odd').css('backgroundImage','none') ;
    
    // Set height
    /*
    if( $('#forum_main ul').height() > $('#calend_main ul').height() )
    	$('#calend_main ul').height( 100 );
    else
    	$('#forum_main ul').height( 100 );
    	*/
	
});

