﻿function blurscreen() {

		 $('#backgroundfade').css('height',screen.height);
		 $('#backgroundfade').fadeIn(500); 

		 }
function quickaccess(){
		 
		$('#quickaccess').toggle(0); 
			$('#quickaccess').bind("mouseleave",function(){ 
			$('#quickaccess').fadeOut(500);
		}); 
		 }
function change_edition(year,number){
		
		$('#frame_loader').fadeIn(500,function(){
			
			$('#frame_loader').html('<img src="imgs/loader.gif" vspace="3" hspace="3" /><br><em>Loading edition...</em>'); 
			});
			setTimeout(function(){
			$('iframe#online-issue').attr('src', 'lib/'+year+'/'+number+'/index.html'); 
			$('iframe#online-issue').ready(function(){
				setTimeout(function(){
					$('#frame_loader').fadeOut(500);
					$('#issue_no').html('Current Edition - '+number);
					},3500);
			},500);
				});
		}
function show_library(state){
	
	if(state=="show")
	{
		blurscreen();
		$('#older_editions').fadeIn(500);
		$.ajax({
		  url: "library.php",
		  success: function(rcode){
			$('#older_editions').html(rcode);
			change_lib_page('1');
		  },
		  error: function(){
			  
			  $('#older_editions').html('<div style="margin-top:180px;"><img src="imgs/warning.png"><br>Older editions not available,<br> please try again later.</div>')
			  }
		});
	}
	if(state=="hide")
	{
	$('#older_editions').fadeOut(500);
	$('#backgroundfade').fadeOut(500); 
	}
		
	}
function change_lib_page(page){
	
	  $.ajax({
	  type:"GET",
	  url: "library_list.php",
	  data: "year="+$("#year option:selected").text()+"&page="+page,
	  success: function(rcode){
		$('#library_list_container').html(rcode);
		if($('#edition_details_container').html()=="")
		{
		show_edition();
		}
	  },
	  error: function(){
		  
		  $('#library_list_container').html('<div style="margin-top:180px;"><img src="imgs/warning.png"><br>Library not available,<br> please try again later.</div>')
		  }
	});
		
	}
function show_edition(edition){
	
	  if(edition == undefined)
	  {var edition ="";}
	  $.ajax({
	  type:"GET",
	  url: "edition_details.php",
	  data: "&edition="+edition+"&year="+$("#year option:selected").text(),
	  success: function(rcode){
		$('#edition_details_container').html(rcode);
	  },
	  error: function(){
		  
		  $('#library_list_container').html('<div style="margin-top:180px;"><img src="imgs/warning.png"><br>Edition not available,<br> please try again later.</div>')
		  }
	});
		
	}
function IEVersion(){
	var _n=navigator,_w=window,_d=document;
	var version="NA";
	var na=_n.userAgent;
	var ieDocMode="NA";
	var ie8BrowserMode="NA";
	// Look for msie and make sure its not opera in disguise
	if(/msie/i.test(na) && (!_w.opera)){
		// also check for spoofers by checking known IE objects
		if(_w.attachEvent && _w.ActiveXObject){		
			// Get version displayed in UA although if its IE 8 running in 7 or compat mode it will appear as 7
			version = (na.match( /.+ie\s([\d.]+)/i ) || [])[1];
			// Its IE 8 pretending to be IE 7 or in compat mode		
			if(parseInt(version)==7){				
				// documentMode is only supported in IE 8 so we know if its here its really IE 8
				if(_d.documentMode){
					version = 8; //reset? change if you need to
					// IE in Compat mode will mention Trident in the useragent
					if(/trident\/\d/i.test(na)){
						ie8BrowserMode = "on";
					// if it doesn't then its running in IE 7 mode
					}else{
						ie8BrowserMode = "off";
					}
				}
			}else if(parseInt(version)==8){
				// IE 8 will always have documentMode available
				if(_d.documentMode){ ie8BrowserMode = "off";}
			}
			// If we are in IE 8 (any mode) or previous versions of IE we check for the documentMode or compatMode for pre 8 versions			
			ieDocMode = (_d.documentMode) ? _d.documentMode : (_d.compatMode && _d.compatMode=="CSS1Compat") ? 7 : 5;//default to quirks mode IE5				   			
		}
	}
				 
	return ie8BrowserMode;		
}
function show_compat_warning()
{
	
$.ajax({
	  url: "compat.html",
	  success: function(rcode){
		$('#compatwarning').html(rcode);
		$('#compatwarning').fadeIn(500);
	  }
	});
}
function download_pdf(edition){

if(edition=="current")
{
var edition = $('#issue_no').html().split(" ");
var edition = edition[edition.length-1];
}
	$('iframe#download-issue').attr('src', 'download_pdf.php?edition='+edition); 
}

$(document).ready(function() {
  if(IEVersion()=="on")
  {
	 blurscreen()
	 show_compat_warning();
  }
});


