$(document).ready(function(){ 
	$("ul.sf-menu").superfish({
		autoArrows:  false,
		delay:       400,                             // one second delay on mouseout 
		animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
		speed:       'fast',                          // faster animation speed 
		autoArrows:  false,                           // disable generation of arrow mark-up 
		dropShadows: false                            // disable drop shadows 			
	});
	
	$('.topnav ul').children('li').each(function() {
		$(this).children('a').html('<span>'+$(this).children('a').text()+'</span>'); // add tags span to a href
	});
	
	// init block
	var className = '.header_box'; // name parent block
	var TimeS = 1000; // time slide block
	var countZ = 0; // count slide tabs
	// progress
	countZ = $('.header_box').children('div').size(); // count slide tabs
	SizeWindow();
	$(window).resize(function() {
		SizeWindow();
	});
	function SizeWindow() {
		$(className).css('width',$(window).width());
	}
	$(className).each(function (i) {
		$(this).css({'display':(i == 0 ? 'block' : 'none'), 'left':'0', 'opacity':(i == 0 ? 1 : 0), 'top':'0', 'z-index':countZ-i});
	});
	$('a[rel=left]').click(function () {
		thisObj = $(this).parents(className);				
		$(className).each(function (i) {
			if ($(this).css('z-index') == parseInt(thisObj.css('z-index')-1)) {
				$(this).css({'display':'block'}).stop().animate({'opacity':1}, TimeS, function() {
					$(this).css({'z-index':countZ});
				});
			} else if ($(this).css('z-index') == thisObj.css('z-index')) {
				$(this).stop().animate({'opacity':0}, TimeS, function() {
					$(this).css({'z-index':countZ-(countZ-1), 'display':'none'});
				});
			} else {
				$(this).stop().animate({'opacity':0}, TimeS, function() {
					$(this).css({'z-index':parseInt($(this).css('z-index'))+1, 'display':'none'});
				});
			}
		});
		return false;
	});
	$('a[rel=right]').click(function () {
		thisObj = $(this).parents(className);				
		$(className).each(function (i) {
			if ($(this).css('z-index') == parseInt(thisObj.css('z-index')-(countZ-1))) {
				$(this).css({'display':'block'}).stop().animate({'opacity':1}, TimeS, function() {
					$(this).css({'z-index':countZ});
				});
			} else if ($(this).css('z-index') == thisObj.css('z-index')) {
				$(this).stop().animate({'opacity':0}, TimeS, function() {
					$(this).css({'z-index':parseInt($(this).css('z-index'))-1, 'display':'none'});
				});
			} else {
				$(this).stop().animate({'opacity':0}, TimeS, function() {
					$(this).css({'z-index':parseInt($(this).css('z-index'))-1, 'display':'none'});
				});
			}
		});
		return false;
	});
});
