function setBookMark(){
	termek_id = $j('#termek_id').val();
	var url="index.php?option=com_whp&controller=reader&task=setBookMark&format=raw";
	url += "&termek_id="+termek_id;
	
	$j.ajax({
      url: url,
      type: "POST",
      async: false,
      success: function(response){
      //alert(url); 	
		 var resp= $j.parseJSON( response );
		 if( resp.error == '' ){
   				 $j.fancybox(resp.html,	{"zoomSpeedIn":300,"zoomSpeedOut":300,"overlayShow":true, "overlayColor":"#000", "overlayOpacity":0.8,'autoDimensions': false,'width' : 350,	'height' : 'auto'});
		 }else{
			alert(resp.error);
		 }
      }
	}); 

}


function getPageSelect(format){
	pagenum = $j("#pageselect").val();
	switch (format){
		case 'epub': getEpubPage(pagenum);
			break;
		default: getPage(pagenum);
	}
	
}

function getPage(pagenum){
	termek_id = $j('#termek_id').val();
	var url="index.php?option=com_whp&controller=reader&task=getPage&format=raw";
	//alert(url);
	url += "&pagenum="+pagenum;
	url += "&termek_id="+termek_id;
	//alert(url);
	$j.ajax({
      url: url,
      type: "POST",
      async: false,
      success: function(response){
      //alert(url); 	
		 var resp= $j.parseJSON( response );
		 if( resp.error == '' ){
			
			$j("#ajaxContentReader .page img").fadeOut(600, function() {
				$j("#ajaxContentReader").html( resp.html );
				
			});
			

		 }else{
			alert(resp.error);
		 }
      }
	 
	});
	setFrameHeight(); 
  		
	
} 

function setFrameHeight(){
	  var height = $j('#ajaxContentReader .page img').height()+20;
		//alert(height);  
		if (height < 900){ height = 900;}
		if (height !=0 ){
			$j('#a_next').height(height);
			$j('#a_prev').height(height);
		}
}
function getEpubFejezet(src){
	termek_id = $j('#termek_id').val();
	var url="index.php?option=com_whp&controller=reader&task=getEpubFejezet&format=raw";
	url += "&src="+src;
	url += "&termek_id="+termek_id;
	//alert(url);
	$j.ajax({
      url: url,
      type: "POST",
      async: false,
      success: function(response){
      //alert(url); 	
		 var resp= $j.parseJSON( response );
		 if( resp.error == '' ){
			
			$j("#ajaxContentReader").fadeOut(500, function() {
        		 $j("#ajaxContentReader").html( resp.html );
				setIframeHeight();
				//sizeIFrame(); 
				//$j("#contentFrame").load(sizeIFrame);
				

			});
			$j("#ajaxContentReader").fadeIn(500); 
		 }else{
		 
			alert(resp.error);
		 }
      }
	});
}

function getEpubPage(pagenum,anch){
	termek_id = $j('#termek_id').val();
	var url="index.php?option=com_whp&controller=reader&task=getEpubPage&format=raw";
	url += "&pagenum="+pagenum;
	url += "&termek_id="+termek_id;
	if (anch != undefined){url += "&anchor="+anch;}
	//alert(url);
	$j.ajax({
      url: url,
      type: "POST",
      async: false,
      success: function(response){
      //alert(url); 	
		 var resp= $j.parseJSON( response );
		 if( resp.error == '' ){
			
			$j("#ajaxContentReader").fadeOut(500, function() {
        		 $j("#ajaxContentReader").html( resp.html );
				setIframeHeight();
				//sizeIFrame(); 
				//$j("#contentFrame").load(sizeIFrame);
				

			});
			$j("#ajaxContentReader").fadeIn(500); 
		 }else{
		 
			alert(resp.error);
		 }
      }
	});
}

function setIframeHeight(){
	 var height = $j('#ajaxContentReader').height()+10;
		//alert(height);  
		if (height < 900){ height = 900;}
		if (height !=0 ){
			$j('#ajaxContentReader iframe').height(height);
			$j('#a_next').height(height+10);
			$j('#a_prev').height(height+10);
	}
}


$j('*').keydown(function(event) {
	//alert('fdsa');
	var irany = '';
	
	
	if (event.keyCode == '33' || event.keyCode == '39' || event.keyCode == '32'){ 	
		if ($j("#ajaxContentReader .page").children().first().is("img")){
			getPage('next');
		} else {
			getEpubPage('next');	
		}
}
	if (event.keyCode == '34' || event.keyCode == '37'){	
		if ($j("#ajaxContentReader .page").children().first().is("img")){
			getPage('prev');
		} else {
			getEpubPage('prev');	
		}
}
	
	

});
$j(document).ready(function() {setIframeHeight(); });
/* $j(document).keypress(function(e) {
      switch(e.keyCode) { 
         // User pressed "up" arrow
         case 38:
            navigate('up');
         break;
         // User pressed "down" arrow
         case 40:
            navigate('down');
         break;
         // User pressed "enter"
         case 13:
            if(currentUrl != '') {
               window.location = currentUrl;
            }
         break;
      }
   });
   */
