$(document).ready(function() {
	//
	$('a[rel=_blank]').live('click', function(){
		this.target = "_blank";
	});


	//
	$("#content form.default2 ul > li:even").addClass('even');
	

	//
	(function() {
		var $formVersion = $('#formVersionSelection');
		
		if ( $formVersion.length>0 ) {	
			var $person = $('#prywatna', $formVersion);
			var $company = $('#firma', $formVersion);
			
			if ( $person.length>0 && $company.length>0 ) {
				var $ul = $formVersion.parents('ul');
				
				$person.click( function() {
					$('li', $ul).removeClass('even');
					
					
					$('li.personOnly', $ul).show();
					$('li.companyOnly', $ul).hide();
					
					$('li:visible:even', $ul).addClass('even');
				});
				
				$company.click( function() {
					$('li', $ul).removeClass('even');
					
					$('li.personOnly', $ul).hide();
					$('li.companyOnly', $ul).show();
					
					$('li:visible:even', $ul).addClass('even');
				});
				
				
				if ( $company[0].checked ) {
					$company.trigger('click');
				} else {
					$person.trigger('click');
				}
			
				
			}
		}
	})();
	

	//
	var cont = $('.catList .catListInner');
	if ($('.catListInner > .catListCol').length > 4) {
		var col0 = $('.catListInner > .catListCol:nth-child(4n)');
		var col1 = $('.catListInner > .catListCol:nth-child(4n+1)');
		var col2 = $('.catListInner > .catListCol:nth-child(4n+2)');
		var col3 = $('.catListInner > .catListCol:nth-child(4n+3)');
		col0.wrapAll('<div class="catListRow"></div>');
		col1.wrapAll('<div class="catListRow"></div>');
		col2.wrapAll('<div class="catListRow"></div>');
		col3.wrapAll('<div class="catListRow"></div>');
		}
	if ($('.catListInner > .catListCol').length > 3) {
		var col0 = $('.catListInner > .catListCol:nth-child(3n)');
		var col1 = $('.catListInner > .catListCol:nth-child(3n+1)');
		var col2 = $('.catListInner > .catListCol:nth-child(3n+2)');
		col0.wrapAll('<div class="catListRow"></div>');
		col1.wrapAll('<div class="catListRow"></div>');
		col2.wrapAll('<div class="catListRow"></div>');
	}


    //
	$('#header input[type="text"]').each(function() {
		var defaultValue = this.value;
		$(this).focus(function() {
			if(this.value == defaultValue) {
				this.value = '';
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
				this.value = defaultValue;
			}
		});
	});


	//
	$('.table1 thead tr th span.openClose').each(function() {
		if ( $(this).hasClass('open') ) {
			$(this).parents('table').find('tbody tr td span.openClose').addClass('open');
			$(this).parents('table').find('tbody.sub').show();
		} else {
		}
	});
	$('.table1 thead tr th span.openClose').click(function() {
		console.log ( $(this).parents('table').find('tbody.sub') );
		
		if ( $(this).hasClass('open') ) {
			$(this).parents('table').find('tbody tr td span.openClose').removeClass('open');
			$(this).parents('table').find('tbody.sub').hide();
			$(this).removeClass('open');
		} else {
			$(this).parents('table').find('tbody tr td span.openClose').addClass('open');
			$(this).parents('table').find('tbody.sub').show();
			$(this).addClass('open');
		}
	});
	$('.table1 tbody tr td span.openClose').each(function() {
		if ( $(this).hasClass('open') ) {
			$(this).parents('tbody').next().show();
		} else {
		}
	});
	$('.table1 tbody tr td span.openClose').click(function() {
		if ( $(this).hasClass('open') ) {
			$(this).parent().parent().parent().next().hide();
			$(this).removeClass('open');
		} else {
			$(this).parent().parent().parent().next().show();
			$(this).addClass('open');
		}
	});


	//
	$('a[rel="colorbox"]').colorbox({rel:'nofollow'});


	//
	$('#content .cbShops .shop').click(function(){
		var hf = $(this).find('a').eq(0).attr('href');
		location.href = hf;
	});
	
	
	//
	if (($.browser.webkit)){
		$('html').addClass('webkit');
	}

	//
	if (($.browser.opera)){
		$('html').addClass('opera');
	}


	//
	if (($.browser.msie) && ($.browser.version <= "8.0")){

		// CSS3PIE
		var CSS3PIE_selectors = [
			'#content form.default3 fieldset input[type="submit"]',
			'#content table.table2 span',
			'#content .button2',
			'#content form.default2 fieldset input',
			'#content form.default2 fieldset ul li',
			'#content .table1 tbody.sub tr td table tbody tr td span',
			'#content .table1 tbody.sub tr td table thead tr th span',
			'#sidebar form input',
			'#sidebar .tree .up',
			'#content .products .product table.info td .btn',
			'#content .pagination li a',
			'.cbShops .shop',
			'#content .dailyOffer a.btn',
			'#content .dailyOffer .box',
			'#content .dailyOffer h4',
			'#content .button',
			'#header .bottom .tabs li a',
			'#header > .bottom .categories > li > span',
			'#header .searchOptions',
			'#header .searchOptions dd',
			'#header form .top',
			'#header .navTop ul li form fieldset .field input'
		];
		$( CSS3PIE_selectors.join(',') ).each(function() {
			PIE.attach(this);
		});
	}


	//
	if (($.browser.msie) && ($.browser.version == "8.0")){
	}


	//
	if (($.browser.msie) && ($.browser.version == "7.0")){
	}

});

