//This file contains a the drop down menu script, a script to fix the z-index issues that occur with the slider/navs in IE, and initializes the colorbox and innerfade script.

//Drop Down Loader
$(document).ready(function(){

	$("ul.topnav li span").hover(function() { //When trigger hovered over...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").stop().slideDown('fast').show('slow', function(){
			$(this).height("auto");
		}); //Drop down the subnav on click


		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").stop().slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	/*MENUS*/
	/*$('#cats li.active').each(function(){
		//expand to parents
		var p = $(this).parent();
		while(!p.hasClass('categories')){
			p.css('display', 'block');
			p = $(p).parent();
		}
		//digg deep
		var next = $(this).next();
		if (next.is('ul')){
			next.css('display', 'block');
		}
	});*/
	$('.subcat:last', $('.cat_active')).css('border', 'none');
	$('.cat_active').each(function(){
		$('.subcats', this).show();
	});
	$('.subcats2 .subcat2_active').parents('.cat').addClass('cat_active').end()
						.parent().show().
						prev().addClass('subcat_active');
	var sub1 = $('.subcats .subcat_active');
	if ($.browser.msie){
		/* for IE */
		sub1.parent('.subcats2').parent().show();
		sub1.parent().parent().show();
		/* --for IE */	
	}
	sub1.parent().parent().addClass('cat_active');
	sub1.parent().show();
	sub1.next().show();
	$('.sub2'+sub1.attr('id')).show();
	
	/*BUY*/
	/*$('.buynow-form input[type="submit"]').click(function(){
		var f = this.form;
		var id = $('input[name="id"]', f).val();
		var qty = $('input[name="qty"]', f).val();
		$.post('/cart/add', {
			'id': id,
			'qty': qty
		}, function(data){
			if (data.error == ''){
				$('#cart_count').html(data.count);
				$('#cart_sum_val').text(data.sum);
				$.gritter.add({
					title: 'Корзина',
					text: 'Товар успешно добавлен!',
					time: 3000
				});
				top.location = '/cart';
			}else{
				$.gritter.add({
					title: 'Корзина',
					text: data.error
				});
			}
		}, 'json');
		return false;
	});*/
	
	/*CART*/
	$('#cart_recalc').click(function(){
		$('#cart_form').submit();
		return false;
	});
	
	/* VIEW */
	$('#view_tab').click(function(){
		$.cookie('view_style', 'table', {'path': '/', 'expires': 356});
		top.location = top.location; 
		return false;
	});
	
	$('#view_list').click(function(){
		$.cookie('view_style', 'list', {'path': '/', 'expires': 356});
		top.location = top.location;
		return false;
	});
	
	//prod images
	$('.prod_images a').fancybox({
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'opacity'		: true,
		'padding'		: 0	
	});
});
