//KOD JEST WŁANOŚCIĄ PROSKLEPY.PL, ZABRONIONE JEST KOPIOWAIE//
function reload(){
	//INPUTS 
	$(".text,.text_small").focus(function () {
		$(this).addClass('focus');  	
	});
	$(".text,.text_small").blur(function () {
		$(this).removeClass('focus');  	
	});

	//CLEAR
	var old;
	$('.clear').click(function(){ 
		old = this.value;
		if( $(this).attr('title') != '1')
			this.value = '';
	}).blur(function () {
		if(this.value == '')
			this.value = old;
		else
			$(this).attr('title', '1');	
	});
	
	//PROPAGE CENTER
	$('.jCenter img').each(function() {
		var width = $(this).attr('width'); 
		var height = $(this).attr('height');
	 	if(width == '0')
			width = $(this).css('width');
		if(height == '0')
			height = $(this).css('height');
		
		$(this).css({left: '50%', marginLeft: -parseInt(width)/2});
		$(this).css({top: '50%',  marginTop : -parseInt(height)/2}); 
		$(this).show();
	}); 
	$('.iq_center img').each(function() {
		var width = $(this).attr('width'); 
		var height = $(this).attr('height');
	 	if(width == '0')
			width = $(this).css('width');
		if(height == '0')
			height = $(this).css('height');
		
		$(this).css({left: '50%', marginLeft: -parseInt(width)/2});
		$(this).css({top: '50%',  marginTop : -parseInt(height)/2}); 
		$(this).show();
	}); 
	
	//ACTIVE 
	$(".iq_hover li").hover(
      function () {
			$(this).addClass('active');
      }, function () {
	  		$(this).removeClass("active");
      }
    );

	 
	//TRACE
 	$('.trace').click(function() {
	$.ajax({
		type: "GET",
		dataType: "html",
		url: jQuery.root+"/ajax/trace.php",
		data: { name: 'Kliknięcie', desc: $(this).attr("title") }
	});});
	
	$('a[target="_blank"]').click(function() {
	$.ajax({
        type: "GET",
		dataType: "html",
        url: jQuery.root+"/ajax/trace.php",
		data: { name: 'Zewnętrzny link' , desc: $(this).attr("href") }
    });});
}

$(document).ready(function(){

	reload(); 
	
	if(php_ajax==false){	
		$(".iq_onChangeSubmit").live('change', function(){
			$(this).parents('form:first').submit(); 
		});
	}
	
	//A SUBMIT
	if(php_ajax==false){
		$(".iq_submit,a.btn_sub").live("click", function(){
		
			var form = $(this).parents('form:first');
			var action = $('<input>').attr({'name':'action', 'type': 'hidden', 'name':$(this).attr('name')}).appendTo(form); 
				form.submit();
			return false; 	
		});
	}
	
	/* FROMS ON ENTER */
	$('.iq_onEnterBlock input').live('keypress', function(e){
		if(e.which == 13){
       	//$(this).find('form:first').submit();
	   		return false;
       	}
     });

	$(".iq_false").live("click", function(){
		return false; 
	});
	
	$(".iq_get").live("click", function(){
		
		var title 		= $(this).attr('title');
		var method		= 'post'
		var dataType 	= 'json';
		var isPage		= false; 
		var isForm 		= false; 
		var isInside	= false;
		var href 		= null; 
		var	data		= null; 
		
		//INSIDE WINDOW
		if($(this).hasClass('iq_isInside')) 
			isInside = true; 	
			
		//PAGE
		if($(this).hasClass('iq_isPage')) 
			isPage = true; 	
		
		//FORM
		if($(this).hasClass('iq_isForm')) 
			isForm = true; 		
		
		if(isForm)
		{
			var form = $(this).parents('form:first');
			var action = $('<input>').attr({'name':'action', 'type': 'hidden', 'value':$(this).attr('name')}).appendTo(form); 
			 href = form.attr('action');
	
			if($(this).attr('href')!=null && $(this).attr('href')!='undefinded' )
				href = href +  $(this).attr('href');
			
			var data = form.serialize(true);
		}
		
		//TITLE		
		if($(this).attr('title').length > 0)
			titleOn = true; 	
		else
			titleOn = false; 
			
		//HREF	
		if($(this).attr('href')!=undefined)
			href = $(this).attr('href');
		
		if(href.length>1 && !isPage) 	
			href_ajax = "&ajax=true";
		else if(isPage)
			href_ajax = "&content"; 
		else
			href_ajax = "?ajax=true"; 
		
		if(href.substr(0, 1)!='/')
			href = '/'+href;
		if(href.substr(1, 1)=='#')
			href = '/'; 
			
		loading = Boxy.get(this);
		
		$.ajax({
		   type: method,
		   dataType: dataType,
		   url:   php_root  + href  + href_ajax,
		   mode: "abort", 
		   data: data,
		   beforeSend: function(data){
				if(isInside)
				{
					loading.setLoading();
					loading.center(); 	
				}
				else
				{
					loading = new Boxy('<div class="loading"></div>', {modal:false}); 
				}
				
		   },
		   error: function(data){
				
				loading.hide();	
		   }, 
		   success: function(res){
				
				eval(res.js);
								
			   	if(res.noload=='null' && res.noload==null && res.noload!='undefinded')			  
			   	{ 
					loading.hide();	 
				}
				else
				{
					if(isPage)
					{
						loading.setContentScrool(res.content);
						loading.center();
						loading.options.titleOn	= true; 
						loading.options.title = $(".boxy-content h1").html(); 
						loading._setupTitleBar(); 
					}
					else
					{					
						loading.setContent2(res.html);
						loading.center();
						
						if(res.title!='null' && res.title!=null && res.title !='undefinded' ) 
							title = res.title;
						
						loading.options.titleOn	= titleOn; 
						loading.options.title = title; 
						loading._setupTitleBar(); 
					}
			   	}
			}
		});
		return false;
	});
});	


