function shareTwitter(title, link){
  window.open('http://twitter.com/home?status=' + title + ': ' + link, 'share');
}
function shareFacebook(title, link){
  window.open('http://www.facebook.com/sharer.php?u=' + link + '&t=' + title, 'share');
}
function shareDraugiem(title, link){
  window.open('http://www.draugiem.lv/say/ext/add.php?link=' + link + '&title=' + title + '&titlePrefix=4sezonas.lv', 'share');
}
function autoSlideBig(){
	var itemCount = $('#randoms-wrap a').length;
	var itemWidth = $('#randoms-wrap a').outerWidth(true);
	if (itemCount > 0){
		$('#randoms-wrap a:first').animate(
			{
				marginLeft: '-' + itemWidth + 'px'
			},
			1000,
			'linear',
			function(){
				$(this).css('margin-left', '0px');
				$('#randoms-wrap').append($(this));
				setTimeout('autoSlideBig()', 2000);
			}
		);
	}
}
var nPrevHighlight = 0;
var nCurrentHighlight = 0;
var nAnimationTimer = 0;
var $highlights;
var $images;
function fadeHightlights(){
	if (nPrevHighlight >= 0 && nPrevHighlight != nCurrentHighlight){
		$highlights.eq(nPrevHighlight).animate({
			marginLeft: '0px',
			opacity: 0.9
		}, 200);
		$images.eq(nPrevHighlight).fadeOut(200);
	}
	
	$highlights.eq(nCurrentHighlight).animate({
		marginLeft: '-4px',
		opacity: 1
	}, 200);
	$images.eq(nCurrentHighlight).fadeIn(200);
}
function autoSwitchHighlight(){
	clearTimeout(nAnimationTimer);
	nAnimationTimer = 0;
	nPrevHighlight = nCurrentHighlight;
	nCurrentHighlight ++;
	if (nCurrentHighlight >= $highlights.size()){
		nCurrentHighlight = 0;
	}
	fadeHightlights();
	// li.active  margin-left:-4px; background:#fff; 
  // li margin-left:0; background:transparent;
  nAnimationTimer = setTimeout('autoSwitchHighlight()', 4000);      
}
function startAutoSwitch(){
	nCurrentHighlight = nPrevHighlight = 0;
	$images.fadeOut(0);
	$highlights.css({
		marginLeft: '0px',
		opacity: 0.9
	});
	fadeHightlights();
  nAnimationTimer = setTimeout('autoSwitchHighlight()', 4000);
}
function manualFade(){
	clearTimeout(nAnimationTimer);
	nPrevHighlight = nCurrentHighlight;
	nCurrentHighlight = parseInt($(this).attr('rel'));
	fadeHightlights();
  nAnimationTimer = setTimeout('autoSwitchHighlight()', 4000); 
}
function showHelp(){
	$('#why-reg').css('display', 'block');
	return false;
}   
$(document).ready(function() {
  var url=window.location;
  var anchor=url.hash.substring(0);  
  $(anchor).addClass("selected");
  
  //setTimeout('autoSlideBig()', 4000);
  
  $highlights = $('#highlights li');
	$images = $('#highlights a.image');
	
	$highlights.mouseover(manualFade);
  startAutoSwitch();
  
	//$('a.close-window').click(hideBoxes);
  $('#poll input[type=radio]').change(function(){
    $('#poll_submit').click();
  });
});

