$(document).ready(function(){
     
    $("#div_content img").each(function (i) {
       var img_href = $(this).attr("src");
       
       if($(this).attr("alt")){
         var title = $(this).attr("alt");
       }else{
         var title = '';
       }

       if (img_href.indexOf('content/images/')!=-1 && img_href.indexOf('content/images/small')==-1){
         $(this).wrap('<a href="'+img_href+'" class="fancybox" title="'+title+'" rel="group"></a>');
       }
     });
     
     $('#div_content a[class=fancybox]').fancybox({'titlePosition' : 'inside', 'SpeedIn': 500, 'SpeedOut': 400, 'overlayShow': true, 'transitionIn' : 'elastic', 'transitionOut' : 'elastic', 'easingIn' : 'easeOutBack', 'easingOut' : 'easeInBack' });
     
     $('a[class=new_page]').fancybox({'autoScale' : false, 'type' : 'iframe', 'width':500,'height':500}); //, 'zoomSpeedIn': 600, 'zoomSpeedOut': 300, 'easingIn' : 'easeOutBack'
     $('a[class=edit]').fancybox({'autoScale' : false, 'type' : 'iframe', 'width':600,'height':550}); //, 'zoomSpeedIn': 600, 'zoomSpeedOut': 500, 'easingIn' : 'easeOutBack', 'easingOut' : 'easeInBack'
     $('a[class=upload_img]').fancybox({'autoScale' : false, 'type' : 'iframe', 'width':850,'height':600}); //, 'zoomSpeedIn': 600, 'zoomSpeedOut': 500, 'easingIn' : 'easeOutBack', 'easingOut' : 'easeInBack'
  
     $("a.submit_buy").click(function(){
         var buy_item = $(this).parent().parent();  //.parent();
         var price = buy_item.find(".price").val();
         var count = buy_item.find(".count").val();
         var izmers = buy_item.find(".izmers").val();
         
         var grozs_cnt = $("#grozs_cnt").html();
         var grozs_cnt = new Number(grozs_cnt);
         grozs_cnt = grozs_cnt + 1;
         $("#grozs_cnt").html(grozs_cnt);         
         
         var buy_item = $(this).parent().parent().parent();
         var path = buy_item.find(".path").val(); 
         var code = buy_item.find(".code").val();
         var name = buy_item.find(".name").val();
         var page_id = buy_item.find(".page_id").val();
         var img_src = buy_item.find(".img_src").val();
         $.ajax({url: "sys/shop_basket.php", data: "path="+path+"&code="+code+"&name='"+name+"'&page_id="+page_id+"&img_src="+img_src+"&price="+price+"&count="+count+"&izmers="+izmers, success: function(response){$("#shop_basket").append(response)}, dataType: "html"});
         return false;
     })
     
     $(".basket_item img").click(function () {
         $(this).fadeOut("fast");
         $(this).fadeIn("normal");
     })
     
     $(".submit_buy img").click(function () {
         $(this).fadeOut("fast");
         $(this).fadeIn("fast");
     })

     
     function remove_item(){
         var grozs_cnt = new Number($("#grozs_cnt").html()); $("#grozs_cnt").html(grozs_cnt - 1);
     
         var index = $(this).parent().find(".index").val();
         $.ajax({url: "sys/shop_basket_remove.php", data: "index="+index, success: function(response){}, dataType: "html"}); //alert(response)
         $(this).parent().parent().fadeOut();
         return false;
     }
   
     $("a.remove_shop_item").click(remove_item)
     
     //$('.buy_item').corner("15px"); 
     
  })
  
/*-----------------------------------------------------------------------------------------------*/

  var DHTML = (document.getElementById || document.all || document.layers);
  
  function getObj(name)
  {
    if (document.getElementById)
    {
   	this.obj = document.getElementById(name);
  	this.style = document.getElementById(name).style;
    }
    else if (document.all)
    {
  	this.obj = document.all[name];
  	this.style = document.all[name].style;
    }
    else if (document.layers)
    {
     	this.obj = document.layers[name];
     	this.style = document.layers[name];
    }
  }
  
  function toggle(id)
  {
  	if (!DHTML) return;
  	var x = new getObj(id);
  	x.style.display = (x.style.display == 'block') ? 'none' : 'block'
  }

  function toggle_page(id,total)
  {
  	if (!DHTML) return;
  	
  	for (var i=1;i<=total;i++){
		  var x = new getObj('page_'+i);
		  x.style.display = 'none';
	   	//var x = new getObj('link_page_'+i);
     	//x.style.backgroundColor='FFFFFF';
	   	var x = new getObj('blink_page_'+i);
    	x.style.backgroundColor='#FFFFFF';
    	x.style.color='#000000';
	  }
	  
   	//var x = new getObj('link_'+id);
  	//x.style.backgroundColor='BBCCEE';
  	
   	var x = new getObj('blink_'+id);

  	x.style.backgroundColor='#939393';
  	x.style.color='#FFFFFF';

  	var x = new getObj(id);
  	x.style.display = 'block';
  }

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0'); if (z<0) z = 1; y.splice(z, 0, pnt); if(y[0] == pnt) y.unshift('0'); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}

