var $j = jQuery.noConflict();

$j(document).ready(function() {

	/* ===[ Main menu ]=== */
	$j('header#header nav ul li ul').parent('li').addClass('linkParent');
	
	$j('.linkParent a').addClass('unact');
	$j('.children li a').removeClass('unact');
	
	$j('.unact').click(function() { return false });
	
	$j('header#header nav ul li').hover(function() {
		$j(this).children('ul').slideToggle('fast').css('z-index','10');
	}, function() {
		$j(this).children('ul').hide();
	});
	
	/* ===[ Breadcrumbs ]=== */
	
	var bread = $j('#pageHeader a').size();
	var dot = ' • ';
	$j('#pageHeader a').after('<span>'+dot+'</span>');
	if (bread >= 2) {
		$j('#pageHeader a:first').hide();
		$j('#pageHeader span:first').hide();
	}
	
	/* ===[ Slider]=== */
	$j('#slider ul').cycle({
		sync: 1,
		speed: 500,
		timeout: 5000,
		prev: '#sliderLeft',
		next: '#sliderRight'
	});
	
	$j('#slider img').each(function() {
		$j(this).attr('title','')
	});
	
	/* ===[ News ]=== */
	$j('#newsFeed .more-link').before('<br /><br />');
	
	/* ===[ Text page ]=== */
	$j('#main p:last').css('padding','0');
	
	function equalize() {
		var main = $j('#main').height()+20;
		var aside = $j('#sidebar').height()-20;
		
		if(main > aside) {
			$j('#sidebar').css('height',main+'px');
		} else {
			$j('#main').css('height',+aside+'px');
		}
	};
	
	equalize();
		
	$j('#main ul.galleryDisplay li:first').css('margin-left', +margin+'px');
	
	$j('aside#sidebar ul li.current_page_item').prepend(' • ');
	$j('aside#sidebar ul:not(.sellers) li ul li').prepend(' • ');
	$j('aside#sidebar .children').css('padding-left','10px');
	
	$j('aside#sidebar ul li ul li a:empty').parent('li').hide();
	$j('.page-id-27 aside#sidebar ul li ul').hide();
	
	$j('dd').hide();
	$j('dt').click(function() {
		$j(this).next('dd').slideToggle();
	});
	
	/* ===[ Articles ]=== */
	$j('article.press').children('header').children('h4:empty').parent('header').parent('article').hide();
	
	/* ===[ Products ]=== */
	$j('.productList article.product:eq(2)').css('padding','5px 4px 5px 5px');
	$j('.productList article.product:eq(5)').css('padding','5px 4px 5px 5px');
	$j('.productList article.product:eq(6)').css('padding','5px 5px 4px 5px');
	$j('.productList article.product:eq(7)').css('padding','5px 5px 4px 5px');
	$j('.productList article.product:eq(8)').css('padding','5px 4px 4px 5px');
	
	$j('.productList article.product').hover(function() {
		$j(this).children('div.wrapper').stop().animate({ opacity: 0.5 }, 250);
	}, function() {
		$j(this).children('div.wrapper').stop().animate({ opacity: 1 }, 250);
	});
	
	$j('article.product').click(function() { 
		var url = $j(this).children('div').children('div').children('h3').children('a').attr('href');
		window.location = url;
	});
	
	$j('article.product').css('cursor','pointer');
	
	$j('.wp-paginate').addClass('clearfix');
	
	$j('.wp-paginate li span.current').parent('li').addClass('current-nav');
	
	/* ===[ Footer ]=== */
	var sum = 0;
	$j('footer ul li').each(function() {
		var w = $j(this).width();
		sum += Number(w);
	});
		
	var margin = (950 - sum)/2;
		
	$j('footer ul li:first').css('margin-left', +margin+'px');
	
	/* ===[ Intro ]=== */	
	$j('#validateAge').click(function() {
		var day = $j('#day').val();
		var month = $j('#month').val();
		var year = $j('#year').val();
		
		var today = new Date(); var dd = today.getDate(); var mm = today.getMonth()+1;//January is 0!
		var yyyy = today.getFullYear(); if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm} var today = yyyy+""+mm+""+dd; 
		var user = year + "" + month + "" + day;
		var old = today - user;
		var old = new String(old);
		
		var age = old.slice(0,-4);
		
		if(age >= 18) {
			location.href = 'site/'
			//alert(age);
		} else {
			var height = ($j('body').height()/2);
			$j('.ageError').css('opacity','0.9').fadeIn();
			$j('.ageError p').css('line-height',height+'px');
		};
		
		return false;
	});
	
});
