var oldsearchcontent;
var current_cat_id = 0;
var current_book_id = 0;
var current_site = 0;

function setPartnerActive(select) {
	
	location.href = "/master/index.php?partner_id=" + select.value;
	
}

function searchFieldClear() {
		
		oldsearchcontent = document.getElementById("searchfield").value;
		document.getElementById("searchfield").value = "";
		
	}
	
	function searchFieldRestore() {
		document.getElementById("searchfield").value = oldsearchcontent;
	}
		
function showTitle(bookid) {
		
		var bookimage = document.getElementById("cover"+bookid);
		var booktitle = document.getElementById("title"+bookid);
		var bookdetail = document.getElementById("bookdetail"+bookid);
		
		if(bookimage) bookimage.className = 'bookimageactive';
		if(booktitle) booktitle.className = 'booktitlehover';
		if(bookdetail) bookdetail.className = 'bookpagelinkactive';
		
	}
	
	function hideTitle(bookid) {
		
		var bookimage = document.getElementById("cover"+bookid);
		var booktitle = document.getElementById("title"+bookid);
		var bookdetail = document.getElementById("bookdetail"+bookid);
		
		if(bookimage) bookimage.className = 'bookimage';
		if(booktitle) booktitle.className = 'booktitle';
		if(bookdetail) bookdetail.className = 'bookpagelink';
		
	}
	
	function showBookContainer(bookid, currentbookid) {

		var bookcontainer = document.getElementById("bookviewcontainer"+bookid);
		var bookcontainercurrent = document.getElementById("bookviewcontainer"+current_book_id);
		var contentbgimage = document.getElementById("contentbgimage");
		var contbottom = document.getElementById("bottomcontent");
		var booksidebar = document.getElementById("book_sidebar"+bookid);
		var booksidebarcurrent = document.getElementById("book_sidebar"+current_book_id);
			
		if(contentbgimage) contentbgimage.style.visibility = 'hidden';
		if(contbottom) contbottom.style.visibility = 'hidden';
		
		if(booksidebar) booksidebar.style.visibility = 'visible';
		if(booksidebarcurrent && bookid != current_book_id) booksidebarcurrent.style.visibility = 'hidden';
		if(bookcontainer) bookcontainer.className = 'bookcontainer_visible';
		if(bookcontainercurrent && bookid != current_book_id) bookcontainercurrent.className = 'bookcontainer_hidden';
	}
	
	function hideBookContainer(bookid, currentbookid) {
	
		var bookcontainer = document.getElementById("bookviewcontainer"+bookid);
		var bookcontainercurrent = document.getElementById("bookviewcontainer"+current_book_id);
		var contentbgimage = document.getElementById("contentbgimage");
		var contbottom = document.getElementById("bottomcontent");
		var booksidebar = document.getElementById("book_sidebar"+bookid);
		var booksidebarcurrent = document.getElementById("book_sidebar"+current_book_id);

		//if(contentbgimage) contentbgimage.style.visibility = 'visible';
		if(contbottom) contbottom.style.visibility = 'visible';

		if(booksidebar) booksidebar.style.visibility = 'hidden';
		if(booksidebarcurrent) booksidebarcurrent.style.visibility = 'visible';
		if(bookcontainer) bookcontainer.className = 'bookcontainer_hidden';
		if(bookcontainercurrent) bookcontainercurrent.className = 'bookcontainer_visible';
	}
	
	
	function getNavigation() {
		
		$.get("/script/navigation.php",
		{
			cat_id: current_cat_id,
			book_id: current_book_id
		},
		function(data){
			$(".navi").html(data);
		}
		);
		
	}
	
	function getNavigationOfCat(cat_id) {
		current_cat_id = cat_id;
		getNavigation();
	}
	
	function loadDistribution(book_id) {
		
		$('#bottom').externalInterface({
			method:'loadCountriesfromHTML',
			args:book_id
		});
		
	}
	
	function setBookActive(book_id)
	{
		$(".subactive").addClass("sub");
		$(".subactive").removeClass("subactive");
		var booklink = document.getElementById("subnav"+book_id);
		booklink.className = "subactive";

		current_book_id = book_id;
		loadDistribution(book_id);
	}
	
	$(document).ready(function(){
		getNavigation();

	});
	

