var link=new String(document.location);

if (link.indexOf("nineteen80one.com/en")>=0) {	var lang='en'; var items=6;	}
else if (link.indexOf("nineteen80one.com/pl")>=0) {	var lang='pl'; var items=3;	}

$(document).ready(function() {
	/* -------------------------------- HEADER / SHARE -------------------------------- */
	// randomly select SHARE button
    function rand (n) {
    	return ( Math.floor ( Math.random ( ) * n + 1 ) );
    }
		
	var number = rand (items);
	$('.share').css('background-image', 'url("/template/images/'+lang+'_sharing'+number+'.png")');

    // SHARE functionality
    if (!jQuery.browser.msie) {
    	jQuery('.shareExpanded').css('opacity', 0);

		jQuery('.share').click(function() {
			jQuery('.shareExpanded').css('display', 'block');
			jQuery(this).animate({opacity : 0}, 'slow', function() {jQuery(this).css('display', 'none');});
			jQuery('.shareExpanded').stop().animate({opacity : 1}, 'slow');
		});

		jQuery('.closeShare').click(function() {
			jQuery('.share').css('display', 'block');
			jQuery('.shareExpanded').animate({opacity : 0}, 'slow', function() {jQuery(this).css('display', 'none');});
			jQuery('.share').stop().animate({opacity : 1}, 'slow');
		});
	}
	else {
		jQuery('.share').click(function() {
			jQuery('.shareExpanded').css('display', 'block');
			jQuery(this).css('display', 'none');
		});
		jQuery('.closeShare').click(function() {
			jQuery('.share').css('display', 'block');
			jQuery('.shareExpanded').css('display', 'none');
		});
	}
	
	
	/* -------------------------------- HEADER / MAIN NAV -------------------------------- */
	$('#wrapper #header .menu ul li').not('li.current_page_item').each(function() {
		$(this).children('a').append('<span class="overlay"></span>');
		
		// add hover actions etc
		$(this).children('a').bind({
			mouseenter: function() {
				$(this).children('.overlay').stop().fadeTo(200, 1);
			},
			mouseleave: function() {
				$(this).children('.overlay').stop().fadeTo(200, 0);
			}
		});
	});
	
	/* -------------------------------- HEADER / RSS & Twitter ICON -------------------------------- */
	$('#rssLink, #twitterLink').fadeTo(1, 0.8);
	$('#rssLink, #twitterLink').bind({
			mouseenter: function() {
				$(this).stop().fadeTo(200, 1);
			},
			mouseleave: function() {
				$(this).stop().fadeTo(200, 0.8);
			}
		});
	
	/* -------------------------------- HEADER / LANG CHANGE -------------------------------- */
	$('#changeLang').fadeTo(1, 0.8);
	$('#changeLang').bind({
			mouseenter: function() {
				$(this).stop().fadeTo(200, 1);
			},
			mouseleave: function() {
				$(this).stop().fadeTo(200, 0.8);
			}
		});
	
	/* -------------------------------- MAIN / TABS SYSTEM -------------------------------- */
	if ($('.indexTab').length) {var indexTab=new Array();
		var indexTabButtons='';
		
		// collect all tabs into array
		$('.indexTab').each(function(){
			indexTab.push($(this).children('.indexTabTitle').text());		
		});
		
		// wrap array with html and prepare content
		for (var item in indexTab) {
			indexTabButtons+='<div class="indexTabButton"><div class="overlay"></div>'+indexTab[item]+'</div>';
		}
		
		// insert content into DOM
		indexTabButtons+='<div class="clear"></div>';
		$('.indexTab:eq(0)').before(indexTabButtons);
		
		// set up all except first to OFF
		$('.indexTabButton').not(':eq(0)').addClass('off');
		
		// add click behaviour for new tab buttons
		$('.indexTabButton').click(function(){
			var item=$(this).index();							
			
			$('.indexTab:visible').fadeOut(200, function() {
				$('.indexTab:eq('+item+')').fadeTo(200, 1);
			});	
			
			$('.indexTabButton').addClass('off');
			$(this).removeClass('off');
			$('.indexTabButton.off .overlay').css({"display":"none"}); // resets all overlay items
		});
		
		// add mouseover behaviour to off items
		$('.indexTabButton.off').live('mouseenter mouseleave mousedown', function(event) {
			switch(event.type) {
				case 'mouseover':
					$(this).children('.overlay').stop().fadeTo(200, 0.5);
					break;
				case 'mouseout':
					$(this).children('.overlay').stop().fadeTo(200, 0);
					break;
			}
		});
	}
	
	
	/* -------------------------------- FOOTER / QUOTE -------------------------------- */
	$('.quote').fadeTo(1, 0.01);
	$('.quote').hover(function() {
    	$(this).stop().animate({opacity : 1}, 3000);
    }, function() {
    	$(this).stop().animate({opacity : 0}, 1000);
    });
	
	
	
						   
}); /* #document.ready */
