var days = ['sek','pir', 'ant', 'tre', 'ket', 'pen', 'ses']; 

$(document).ready(function(){
	if ($("#kalendorius").size() > 0) {	
		$("#kalendorius").datepicker('option', 'firstDay', 1);
		
	  	$("#kalendorius").datepicker({
	   		onSelect: function(dateText, inst) {
	   			var myDate = dateText.split("-");
				var d = new Date(myDate[0],myDate[1]-1,myDate[2]); 			   	
	   			window.location = '/laidu-tinklelis/'+dateText+'/#'+days[d.getDay()];						
			}
		});	
	}
		
	
  //Pririsam fake'inius mygtukus prie formu submito
  if ($('.submit_rel').size() > 0) {
	  $('.submit_rel').bind('click', function(){
	  	$($(this).attr('rel')).trigger('submit');
	  });
  }
		
  //Komentaru formu validacija
  if ($('#commentForm').size() > 0) {
	  $('#commentForm').submit(function(){
	  	 var blank_fields = [];
	  	 $('label span', this).each(function(index){
	  		$(this).parents('p').find('input[value=""], textarea[value=""], select[value=""]').each(function(){
	  			blank_fields.push($(this).parents('p').find('label').text());
	  		});
	  	 });
	  	 if(blank_fields.length){
	  	 	alert("Prašome užpildyti privalomus laukus");
	  	 	return false;
	  	 }
	  	 return true;
	  });
  }
		     
if ($('#block_priority').size() > 0) {            
  $('#block_priority').equalHeights();
}
  //$('#block_usernews').equalHeights();
if ($('#block_naujienos').size() > 0) {
  var highestCol = Math.max($('#block_naujienos').height()+1,$('#block_valdziai').height()+1);
  $('#block_naujienos').height(highestCol);
  $('#block_valdziai').height(highestCol);
}
  
if ($("#comment").size() > 0) {  
  $("#comment").charCounter(1000, {container: "#counter"});
}
  
  	d = new Date();
  	var hash = window.location.hash;
	if (!hash) {
		hash = '#'+days[d.getDay()]; 
	}		
	if ($('.grid>li>a[href='+hash+']').size() > 0) {	
		$('.grid>li>a[href='+hash+']').addClass('active');
	}
	if ($('.scroller').size() > 0) {	
		if (hash != '#sek') {	
			$('.scroller').scrollTo(hash, 0, {axsis:'x'} );
		}else {
			$('.scroller').scrollTo('#ses', 0, {axsis:'x'} );
		}
	}
	
		

  if ($('.grid>li>a').size() > 0 ) {
	  $('.grid>li>a').click(function() {
	  	//$('.grid>li>a.active>span').remove();  		
		$('.grid *').removeClass('active');
		
		$(this).addClass('active');
		//$(this).html($(this).html()+'<span> »</span>');	  	
		if ($(this).attr('href') != '#sek')	
	  		$('.scroller').scrollTo($(this).attr('href'), 500, {axsis:'x'} );
	  	else
	  		$('.scroller').scrollTo('#ses', 500, {axsis:'x'} );
	
	  	return false;
	  });
  }
  
  	if ($('.scroller tr').size() > 0) {
		$('.scroller tr').hover(
			function () {
				$(this).addClass("hover");
			},
			function () {
				$(this).removeClass("hover");
			}
		);
	}
	
	if ($('#search_place').size() > 0) {
		$('#search_place').highlight($('#search_query_holder').text());
	}  	
	
	// -- del to, kad blokeliams sudeda ID ipyramid, have chrome issues
  	//$('[id^=block_]').addClass('normaldiv');  	
  	//$('[id^=ox_]').addClass('normaldiv');
  	
  	
  	$('*[title]').inputHint();
	$('#top_menu input[type=text]').inputHint();

	
	
});
