/* -------------------------------------------------- *
 * Project scripts
 * -------------------------------------------------- *
 * Author: Morozov Igor
 * URL: http://www.morozoff.info/
 * Copyright: 2010 Morozov Igor
** -------------------------------------------------- */
var options = {
	target: "#output",
	url: "/bazarmail/",
	type: "POST",
	timeout: 3000
};

var dblk='display:block';
$(document).ready(function() {
	$(".b-forms .i-p, .b-auth-form .i-p, .b-search .i-p").toggleVal();
	$("a.fancybox").fancybox();
	$("a.mstc").click(function() {
	if($("#msites").hasClass('nowis'))
	{$("#msites").removeClass('nowis');}
	else
	{$("#msites").addClass('nowis');}
	return false;
	});
	$("#pmail").click(function() {
	 $('#myForm').attr('style',dblk);
	 if (dblk=='display:block') {dblk='display:none';} else {dblk='display:block';}
	 return false;
	});
	$("#parters-scroll").smoothDivScroll({
		scrollingSpeed: 7,
		mouseDownSpeedBooster: 3,
		autoScroll: "always",
		autoScrollDirection: "backandforth",
		autoScrollSpeed: 1,
		pauseAutoScroll:"mouseover"
	});
	if($('#main-vis').length > 0) {
		var sbtime = 0
		$('#main-vis').everyTime(90,scrollBg);

		$('.b-mnvis-ul li').bind('mouseleave mouseenter', function(event) {
			var evtype = event.type;
			var $t = $(this);
			
			if(evtype == 'mouseenter') {
				clearTimeout(sbtime);
				if(!$t.hasClass('active')) {
					$('.b-mnvis-ul li p').attr('style','display:none');
					$('.b-mnvis-ul li').removeClass('active');
					$t.find('p').stop().animate({height:'show'}, { queue:false, duration:600, complete:function(){
						$t.addClass('active')
					}})
				}
			}
			else {
				sbtime = setTimeout(function(){
					$t.find('p').stop().delay(700).animate({height:'hide'}, { queue:false, duration:600, complete:function(){
						$(this).attr('style','display:none');
						$t.removeClass('active')
					}})
				},700)
			}
		});
		
	}
	if($('a.cat-link').length > 0) {
		var pptime = 0;
		var $ppcat = $('.pp-cat')
		var ppheight = $ppcat.height()+100;
		$ppcat.css('marginTop','-'+ppheight+'px');
		$('a.cat-link').bind('mouseenter', function(event) {
			clearTimeout(pptime);
			$('.top-i').unbind('mouseleave');
			$('.pp-cat').stop().animate({marginTop:0},800, function(){
				$('.top-i').bind('mouseleave', function() {
					pptime = setTimeout(hideppnav,500)
				});
			});
		});
		
		
		$ppcat.bind('mouseleave mouseenter', function(event) {
			var evtype = event.type
			if(evtype == 'mouseenter') {
				clearTimeout(pptime);
				$('.pp-cat').stop().animate({marginTop:0},800)
			}
			else {
				pptime = setTimeout(hideppnav,500)
			}
		});
	}
});

var current = 0;

function hideppnav() {
	var $ppcat = $('.pp-cat');
	var ppheight = $ppcat.height()+100;
	$('.pp-cat').stop().animate({marginTop:'-'+ppheight+'px'},800);
	$('.top-i').unbind('mouseleave');
}

function scrollBg(){
	current += 1;
	$('#main-vis').css("background-position",current+"px 0px");
	//alert('hello')
}
