if( !window.console ) {
	window.console 		 = function(){};
	window.console.log   = function(c) {  };
	window.console.info  = function(c) {  };
	window.console.dir   = function(c) {  };
	window.console.error = function(c) {  }; 
}

(function() {
   jQuery.fn['bounds'] = function () {
     var bounds = {left: Number.POSITIVE_INFINITY, top: Number.POSITIVE_INFINITY,
                   right: Number.NEGATIVE_INFINITY, bottom: Number.NEGATIVE_INFINITY};

     this.each(function (i,el) {
                 var elQ = $(el);

                 if (elQ.length == 0)
                   return;

                 var off = elQ.offset();
                 off.right = off.left + $(elQ).width();
                 off.bottom = off.top + $(elQ).height();

                 if (off.left < bounds.left)
                   bounds.left = off.left;

                 if (off.top < bounds.top)
                   bounds.top = off.top;

                 if (off.right > bounds.right)
                   bounds.right = off.right;

                 if (off.bottom > bounds.bottom)
                   bounds.bottom = off.bottom;

               });
     return bounds;
   }
 })();

   image1 = new Image(); image1.src = "public/images/koszykOn.png";
   
    
    function showhide(id)
    {
      $(id).toggle();
    }

    $(document).ready(function()
    {	
    	var kot = {};
    	kot.top = 20;
    	
    	var twitter = $( '#twitter' );
    	twitter.css({ 
    		width: '200px',
    		position: 'fixed',
    		zIndex: '2005',
    		top: kot.top + 'px',
    		left: '-206px',
    		background: '#ECEFF5',
    		padding: '6px 0px 6px 6px'
    	});

    	var interval;
    	var end = true;
    	var twitter_btn = $('#twitter_btn');
    	twitter_btn.css({
    		width: '30px',
    		height: '100px',
    		position: 'fixed',
    		zIndex: '2006',
    		top: kot.top + 'px',
    		left: '0px',
    		padding: '6px 0px 6px 6px'
    	}).mouseover(function(){
    		window.clearInterval( interval );
    		if( !end ) {
    			return;
    		}
    		end = false;
    		twitter.animate({
    			left: '0px'
    		}, 500);
    		$(this).animate({
    			left: '200px'
    		}, 500,null, function(){
    			end = true;
    		});

    	}).mouseout(function(){
    		interval = window.setTimeout(function(){
        		twitter_btn.animate({
        			left: '0px'
        		}, 500);
        		twitter.animate({
        			left: '-206px'
        		}, 500);
    		},100);
    	});

    	twitter.hover(function(){
    		window.clearInterval( interval );
    	},function(){
    		interval = window.setTimeout(function(){
        		twitter_btn.animate({
        			left: '0px'
        		}, 500);
        		twitter.animate({
        			left: '-206px'
        		}, 500);
    		},100);
    	});
    	

    	//nk
    	var nk = $( '#naszaklasa' );
    	nk.css({ 
    		width: '200px',
    		position: 'fixed',
    		zIndex: '2001',
    		top: parseInt( kot.top + 110 ) + 'px',
    		left: '-206px',
    		background: '#2B608C',
    		padding: '6px 0px 6px 6px'
    	});

    	var interval_nk;
    	var end_nk = true;
    	var nk_btn = $('#naszaklasa_btn');
    	nk_btn.css({
    		width: '30px',
    		height: '100px',
    		position: 'fixed',
    		zIndex: '2002',
    		top: parseInt( kot.top + 110 ) + 'px',
    		left: '0px',
    		padding: '6px 0px 6px 6px'
    	}).mouseover(function(){
    		window.clearInterval( interval_nk );
    		if( !end_nk ) {
    			return;
    		}
    		end_nk = false;
    		nk.animate({
    			left: '0px'
    		}, 500);
    		$(this).animate({
    			left: '200px'
    		}, 500,null, function(){
    			end_nk = true;
    		});

    	}).mouseout(function(){
    		interval_nk = window.setTimeout(function(){
    			nk_btn.animate({
        			left: '0px'
        		}, 500);
        		nk.animate({
        			left: '-206px'
        		}, 500);
    		},100);
    	});

    	nk.hover(function(){
    		window.clearInterval( interval_nk );
    	},function(){
    		interval_nk = window.setTimeout(function(){
    			nk_btn.animate({
        			left: '0px'
        		}, 500);
        		nk.animate({
        			left: '-206px'
        		}, 500);
    		},100);
    	});
    	
    	
    	//fb
    	var fb = $( '#facebook' );
    	fb.css({ 
    		width: '200px',
    		position: 'fixed',
    		zIndex: '1998',
    		top: parseInt( kot.top + 220 ) + 'px',
    		left: '-206px',
    		background: '#3B5998',
    		padding: '6px 0px 6px 6px'
    	});

    	var interval_fb;
    	var end_fb = true;
    	var fb_btn = $('#facebook_btn');
    	fb_btn.css({
    		width: '30px',
    		height: '100px',
    		position: 'fixed',
    		zIndex: '1999',
    		top: parseInt( kot.top + 220 ) + 'px',
    		left: '0px',
    		padding: '6px 0px 6px 6px'
    	}).mouseover(function(){
    		window.clearInterval( interval_fb );
    		if( !end_fb ) {
    			return;
    		}
    		end_fb = false;
    		fb.animate({
    			left: '0px'
    		}, 500);
    		$(this).animate({
    			left: '200px'
    		}, 500,null, function(){
    			end_fb = true;
    		});

    	}).mouseout(function(){
    		interval_fb = window.setTimeout(function(){
    			fb_btn.animate({
        			left: '0px'
        		}, 500);
    			fb.animate({
        			left: '-206px'
        		}, 500);
    		},100);
    	});

    	fb.hover(function(){
    		window.clearInterval( interval_fb );
    	},function(){
    		interval_fb = window.setTimeout(function(){
    			fb_btn.animate({
        			left: '0px'
        		}, 500);
    			fb.animate({
        			left: '-206px'
        		}, 500);
    		},100);
    	});


    	$('.sh').css('cursor','pointer');
    	
      // obsluga menu
      $('.menutop a').mouseover(function(){
         var cl = $(this).attr('class');
         cl = cl.substr(0,2);
         $.cookie('cl', cl);
         if(cl!='')
         {
           $('.menutop a').removeClass('selected');
           $('.menutop a').removeClass('selected2');
           $(this).addClass('selected');
           $('.menudown').show();
           $('.menudown p.me').hide();
           $('.menudown p.'+cl).show();
         }
         else
         {
           $('.menutop a').removeClass('selected');
           $('.menutop a').removeClass('selected2');
           $(this).addClass('selected2');
           $('.menudown p.me').hide();
         }
      });
      
      if($.cookie('cl')!='')
      {
         var cl = $.cookie('cl');
           $('.menutop a.'+cl).addClass('selected');
           $('.menudown').show();
           $('.menudown p.me').hide();
           $('.menudown p.'+cl).show();
      }
      // koniec obslugi menu
      
      // stylizacja <select>
      $('#selectTrans').sSelect();
      $('#selectNgry').sSelect();
      $('#selectNprze').sSelect();

      // kup teraz - wybor allegro
      $('.transType').click(function(){
         
         var val = $(this).attr('value');
         
         if(val==2)
         {
           $('#inputAllegro').show();
           $('#inputNick').html('Nick (nazwa konta z allegro)');
         }
         else
         {
           $('#inputAllegro').hide();
           $('#inputNick').html('Nick');
         }
      });
      $('#transTypeAllegro:checked').each(function(){
           $('#inputAllegro').show();
           $('#inputNick').html('Nick (nazwa konta z allegro)');
      });
      
    }) //end

  function showhide(what)
  {
    $('#'+what).slideToggle();
  }
  
  function sh(what, shide)
  {
    $(what).toggle();

    if(shide!='')  { $(shide).hide(); }
  }

  function potwierdz(text) 
  {
    var potw = confirm('Na pewno chcesz '+ text + ' ?');
    return potw;
  }
function showhide(id)
{
	$('#one_'+id).toggle();
	$('#two_'+id).toggle();
	$('#opis_'+id).toggle("slow");
}
function showhide2()
{
	$('#list1').toggle();
	$('#list2').toggle();
	$('#obraz1').toggle();
	$('#obraz2').toggle();
	$('#opis1').toggle();
	$('#opis2').toggle();
}
function blinkblink()
{
	
	$('#totalsum').effect( 'highlight', {
		color : '#25FF00'
	}, 2000 );
}

function checksearch()
{
	if($.trim($('#ssser').val()) == '')
		alert('Nie podałeś żadnej frazy do wyszukiwania');
	else 
	{
		$('#ser').attr('action', 'games/buylistsearch') ;
		//alert($('#ser').attr('action'));
		$('#ser').submit();
	}
}
function sprawdz_wysylke(par)
{
	var form = $('#basketForm');
	
	var reqText  = /^[a-zA-Z0-9\-\_]{3,30}$/;
	var reqEmail = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
	var reqTel   = /^[0-9]{9}$/;        
	var reqgg   = /^[0-9]*$/;  
	   //console.log(reqEmail);                                               
	
	var email = form.find( '#email' );
	email.attr('value', email.val().toLowerCase());
	var malymail = email.val().toLowerCase();
	var rules = form.find( '#rules' );
	var tel   = form.find( '#sms' );
	var gadugadu   = form.find( '#gadugadu' );
	
	if( !this.appendErrors ) {
		this.emailError = $( '<div id="pe2" class="paidFormError">' + email.attr( 'errorinfo' ) + '</div>' );
		this.rulesError = $( '<div id="pe3" class="paidFormError">' + rules.attr( 'errorinfo' ) + '</div>' );
		this.telError   = $( '<div id="pe4" class="paidFormError">' + tel.attr( 'errorinfo' ) + '</div>' );
		this.ggError    = $( '<div id="pe5" class="paidFormError">' + gadugadu.attr( 'errorinfo' ) + '</div>' );
		
		$('#blad1').append( this.nickError );
		$('#blad1').append( this.emailError );
		$('#blad3').append( this.rulesError );
		$('#blad2').append( this.telError );
		$('#blad5').append( this.ggError );
		this.appendErrors = true;
	}
	
	var errors = 4;
	
	/*
	if( !reqText.test( nick.val() ) ) {
		var bounds = nick.bounds();
		this.nickError.css({
	        left: parseInt( bounds.left, 10 ) + 'px',
	        top: parseInt( bounds.top + 26, 10 ) + 'px',
	        display: 'block'
		});
	} else {
		this.nickError.css({display: 'none'});
		errors--;
	}
	*/
	
	if( !reqEmail.test( malymail ) ) {
		var bounds = email.bounds();
		this.emailError.css({
	        display: 'block'
		});
	} else {
		this.emailError.css({display: 'none'});
		errors--;
	}

	if( !rules.is( ':checked' ) ) {
		var bounds = rules.bounds();
		this.rulesError.css({
	        display: 'block'
		});
		rules.attr( 'value', 0 );
	} else {
		rules.attr( 'value', 1 );
		this.rulesError.css({display: 'none'});
		errors--;
	}
	//alert(malymail);
	if( tel.val() && !reqTel.test( tel.val() ) ) {
		var bounds = tel.bounds();
		this.telError.css({
	        display: 'block'
		});
	} else {
		this.telError.css({display: 'none'});
		errors--;
	}
	if( gadugadu.val() && !reqgg.test( gadugadu.val() ) ) {
		var bounds = gadugadu.bounds();
		this.ggError.css({
	        left: parseInt( bounds.left, 10 ) + 'px',
	        top: parseInt( bounds.top + 26, 10 ) + 'px',
	        display: 'block'
		});
	} else {
		this.ggError.css({display: 'none'});
		errors--;
	}
	if( errors == 0 ) {
		$('#header2').attr('value',par);
		form.attr('action',baseadres + '/basket');
		
		form.submit();
	}
}