function getIEVersion() {
   var rv = -1; // Return value assumes failure.
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
}

function pageselectCallbackHighlights(page_index, jq){
	var new_content = jQuery('#osszes_highlights div.highlightoldal:eq('+page_index+')').clone();
	$('#highlights').empty().append(new_content);
	return false;
}

function pageselectCallbackCategories(page_index, jq){
	var new_content = jQuery('#osszes_category div.categoryoldal:eq('+page_index+')').clone();
	$('#categorypages').empty().append(new_content);
	return false;
}


function initHighlightsPagination() {
	var num_entries = jQuery('#osszes_highlights div.highlightoldal').length;
	$("#highlightslapozas").pagination(num_entries, {
		callback: pageselectCallbackHighlights,
		items_per_page:1
	});
	
	$("#highlightslapozas2").pagination(num_entries, {
		callback: pageselectCallbackHighlights,
		items_per_page:1
	});
}

function initCategoryPagination() {
	var num_entries = jQuery('#osszes_category div.categoryoldal').length;
	$("#categorylapozas").pagination(num_entries, {
		callback: pageselectCallbackCategories,
		items_per_page:1
	});
	$("#categorylapozas2").pagination(num_entries, {
		callback: pageselectCallbackCategories,
		items_per_page:1
	});
	
}
function renewal(id, state){
	var ie = getIEVersion();
	if ((ie==-1) || (ie>=8.0)) {
		if (state=="yes"){cssclass="renewal_yes";}
		if (state=="no"){cssclass="renewal_no";}
		if (state==""){cssclass="";}
		$("#renewal_row_"+id).removeClass("renewal_yes");
		$("#renewal_row_"+id).removeClass("renewal_no");
		$("#renewal_row_"+id).addClass(cssclass);
	}
}

function getURLParameter( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function loadContent(what, where, scenario, lang, data) {
	$.ajax({
		url : what,
		type : "POST",
		data : '&scenario='+scenario+'&lang='+lang+'&data='+data,
		cache : false,
		success : function (html) {
			$(where).html(html);
		}
	});
}

$(document).ready(function(){
	initHighlightsPagination();
	initCategoryPagination();
//	loadContent('/recommend.jsp', '#onnek_ajanljuk', '', langCode, data);
	if (targetAnchor!="") {
		/*alert(targetAnchor);*/
		window.location.hash=targetAnchor; 	
	}
	if (highlightid!=""){
		//openObj lesz az aktuális highlightoldal.
		openObj = $('#'+highlightid).parents('.highlightoldal:first');
		page = $(".highlightoldal").index(openObj);
		if (page>0) {
			page=page-1;
		}
		$("#highlightslapozas").trigger('setPage', [page]);
	}
});

function getCalendar(month, place, day, lang) {
	$.ajax({
		url : "/calendar.jsp", 
		type : "POST",
		data : '&month='+month+"&place="+place+"&lang="+lang+"&day="+day,
		cache : false,
		success : function (html) {
			$("#calendar").html(html);
		}
	});
}

$(function(){
	//Get our elements for faster access and set overlay width
	var div = $('div.sc_menu'),
		ul = $('ul.sc_menu'),
		ulPadding = 15;
	
	//Get menu width
	var divWidth = div.width();
 
	//Remove scrollbars	
	div.css({overflow: 'hidden'});
	
	//Find last image container
	var lastLi = ul.find('li:last-child');
	
	//When user move mouse over menu
	div.mousemove(function(e){
		//As images are loaded ul width increases,
		//so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});

