Event.observe(window, 'load', function(){
	myurl = new haponUrl;
	//current selection
	var current = parseInt(myurl.getUrl("|"));
	var fromWhere = myurl.getUrl("#");
	var fromWHereFlag = fromWhere.substr(0,11);
	if(current >=1){
		if(fromWHereFlag == 'recipeOfDay'){
			myurl.setLinks("pRecipeClickNext","pRecipeClickPrev",current,"recipeOfDay");
			if(current>=1) $('pRecipeClickNext').update('<span class="prevNextBtn">NEXT</span>');
			getAjax("getRecipeoftheday/"+current, "recipeOfTheDay", "");
		}else if(fromWHereFlag == 'popularReci'){
			myurl.setLinks("recipesByPopularNext","recipesByPopularPrev",current,"popularRecipes");
			getAjax("getRecipeByRating/"+current, "recipesByRatingData", "");
		}else if(fromWHereFlag == 'popularView'){
			myurl.setLinks("recipesByViewNext","recipesByViewPrev",current,"popularView");
			getAjax("getPopularView/"+current, "recipesByPop", "");
		}
	}
	var hash = window.location.href;
	setInterval(function(){
		if (window.location.href != hash){
			var backButton = parseInt(myurl.parseEndString(location.hash,"|"));
			if(!(isNaN(backButton))){
				var from = myurl.parseEndString(location.hash,"#");
				var flg = from.substr(0,11);
				if(flg=="recipeOfDay"){
					getAjax("getRecipeoftheday/"+backButton, "recipeOfTheDay", "");
				}else if(flg=="popularReci"){
					getAjax("getRecipeByRating/"+backButton, "recipesByRatingData", "");
				}else if(flg =='popularView'){
					getAjax("getPopularView/"+backButton, "recipesByPop", "");
				}
				if(backButton > 2 && backButton < numpage){
					//alert(backButton);
					numRowsListing = ' <a href="'+host+'#popularView|'+(backButton-1)+'" class="">'+(backButton-1)+'</a> ';	
					numRowsListing += ' <a href="'+host+'#popularView|'+(backButton)+'" class="">'+(backButton)+'</a> ';
					numRowsListing += ' <a href="'+host+'#popularView|'+(backButton+1)+'" class="">'+(backButton+1)+'</a> ';
					$('numRowsListing').update(numRowsListing);
				}
			}
			hash = window.location.href;
		}
	}, 100);
	
	
	/*$('pRecipeClickPrev').onclick = function(){
		var page = parseInt(myurl.parseEndString($(this).getAttribute("href"), "|"));
		$(this).setAttribute("href",host+"#recipeOfDay|"+(page + 1) );
		$('pRecipeClickNext').setAttribute("href",host+"#recipeOfDay|"+(page+1) );
		if(page >= 0)$('pRecipeClickNext').update('<span class="prevNextBtn">NEXT</span>');
		$('mainInfoRightBox2').addClassName("flashboxLoader");
		pageTracker._trackPageview("/Request/recipeOfTheDay/"+page);
	}
	
	$('pRecipeClickNext').onclick = function(){
		var page = parseInt(myurl.parseEndString($(this).getAttribute("href"), "|"));	
		$(this).setAttribute("href",host+"#recipeOfDay|"+(page-1) );
		$('pRecipeClickPrev').setAttribute("href",host+"#recipeOfDay|"+ (page - 1) );	
		if((page-1) == 0)$(this).update("");
		$('mainInfoRightBox2').addClassName("flashboxLoader");
		pageTracker._trackPageview("/Request/recipeOfTheDay/"+page);
	}*/
	
	
	$('recipesByPopularNext').onclick = function(){
		var page = parseInt(myurl.parseEndString($(this).getAttribute("href"), "|"));
		$(this).setAttribute("href",host+"#popularRecipes|"+(page + 1) );	
		$('recipesByPopularPrev').setAttribute("href",host+"#popularRecipes|"+(page+1) );
		if(page >= 0)$('recipesByPopularPrev').update('<span class="prevNextBtn">NEXT</span>');
		$('mainInfoRightBox3').addClassName("flashboxLoader");
		pageTracker._trackPageview("/Request/topfive/"+page);
	}
	$('recipesByPopularPrev').onclick = function(){
		var page = parseInt(myurl.parseEndString($(this).getAttribute("href"), "|"));	
		$(this).setAttribute("href",host+"#popularRecipes|"+(page-1) );
		$('recipesByPopularNext').setAttribute("href",host+"#popularRecipes|"+ (page - 1) );
		if((page-1) == 0)$(this).update("");
		$('mainInfoRightBox3').addClassName("flashboxLoader");
		pageTracker._trackPageview("/Request/topfive/"+page);
	}

	$('recipesByViewNext').onclick = function(){
		var page = parseInt(myurl.parseEndString($(this).getAttribute("href"), "|"));
		if(page < numpage){
			$(this).setAttribute("href",host+"#popularView|"+(page + 1) );	
			$('recipesByViewPrev').setAttribute("href",host+"#popularView|"+(page+1) );
			if(page >= 0)$('recipesByViewPrev').update('<span class="prevNextBtn">NEXT</span>');
			$('mainInfoRightBox4').addClassName("flashboxLoader");
			pageTracker._trackPageview("/Request/mostviewed/"+page);
		}
	}
	$('recipesByViewPrev').onclick = function(){
		var page = parseInt(myurl.parseEndString($(this).getAttribute("href"), "|"));	
		$(this).setAttribute("href",host+"#popularView|"+(page-1) );
		$('recipesByViewNext').setAttribute("href",host+"#popularView|"+ (page - 1) );
		if((page-1) == 0)$(this).update("");
		$('mainInfoRightBox4').addClassName("flashboxLoader");
		pageTracker._trackPageview("/Request/mostviewed/"+page);
	}

})