var activeNav = 0;
$(document).ready(function(){
	$('.hide').hide();
});

function updatePublishing(cat, character, numb) {
	
	//getBookThumb(0);
	getPressItems(cat, character, numb);
	getAlphabet(cat);
	sIFR.callbacks['.publicationLink td'][activeNav].changeCSS({
			'.sIFR-root': {'font-weight': 'bold'},
			'a': {'color': '#545454','text-decoration': 'none'},
			'a:hover': {'color': '#000000'}
		});
		
		sIFR.callbacks['.publicationLink td'][numb].changeCSS({'.sIFR-root': {'font-weight': 'bold'},
			'a': {'color': '#000000','text-decoration': 'none'},
			'a:hover': {'color': '#000000'}
		});
		activeNav = numb;
}

function updateLibrary(cat, character) {
	getLibraryItems(cat, character);
	getAlphabet(cat);
}

function thisMovie(movieName) {
		 if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }
function sendToActionScript(val) {
       if (navigator.appName.indexOf("Microsoft") != -1) {
	  	//since this does not work, must to this
		$('.publishNav #letter').empty().html('<div class="charLet">'+val+'</div>');
	  } else {
	  	thisMovie("letter").sendToActionScript(val);
	  }
	  
}
function getPressItems(cat,character,numb) {
	$('#rightContent').css("min-height",$('#rightContent').height());
	
	$('.libList').css('background','#ffffff').fadeOut(400, function() {
		
		if(character == undefined) {
			var params = {'category': cat};
			$('.publishNav .letter').html('');
			
			
		} else {
			var params = {'category': cat, 'character': character};
			$('.alphabet .chars .active').removeClass('active').addClass('inactive');
			$('.alphabet .chars #alphabetNavLetter'+character).removeClass('inactive').addClass('active');	
			sendToActionScript(character);
			
		}
		$.get('../pages/functions/getPressItems.php', params, function(data) {
			activeNav = numb;
			
			$('.libList').html(data).css('background','#ffffff').fadeIn(400);	
			$('.hide').hide();		
		});
		
		if(character == undefined || character < 1) {
			sIFR.callbacks['.publicationLink td'][activeNav].changeCSS({
				'.sIFR-root': {'font-weight': 'bold'},
				'a': {'color': '#545454','text-decoration': 'none'},
				'a:hover': {'color': '#000000'}
			});
			
			sIFR.callbacks['.publicationLink td'][numb].changeCSS({'.sIFR-root': {'font-weight': 'bold'},
				'a': {'color': '#000000','text-decoration': 'none'},
				'a:hover': {'color': '#000000'}
			});	
		}
		
		
		
	});
}
function getAlphabet(cat){
	$('#alphabetContainer').css("min-height", $('#alphabetContainer').height());
	$('.alphabet').fadeOut(400, function() {
		$.get('../pages/functions/getPressAlphabet.php', {'category': cat}, function(data) {
			
			$('#alphabetContainer').html(data).css('background','#ffffff').fadeIn(400);	
			$('.hide').hide();
		});
	});
}

function readyToClose() {
	$('#bookInfo #enlarge').bind("click", function() {
		
	$('#bookInfo #enlarge').unbind();
	$('#enlarge img').attr({src:'../img/icn_enlarge_wt.gif'});
	$('#enlarge').bind("mouseover", function() { $('#enlarge img').attr({src:'../img/icn_enlarge_rd.gif'}); });
	$('#enlarge').bind("mouseout", function() { $('#enlarge img').attr({src:'../img/icn_enlarge_wt.gif'}); });
		
		
	$('#bookInfo p').slideDown(400);
	$('.largeImg').slideUp(500);
	$('.medImg').slideDown(400);
	
	readyToEnlarge();		
	});
}

function readyToEnlarge() {
	$('#bookInfo #enlarge').bind("click", function() {
		$('#bookInfo #enlarge').unbind();
		$('#enlarge img').attr({src:'../img/icn_close_wt.gif'});
		$('#enlarge').bind("mouseover", function() { $('#enlarge img').attr({src:'../img/icn_close_rd.gif'}); });
		$('#enlarge').bind("mouseout", function() { $('#enlarge img').attr({src:'../img/icn_close_wt.gif'}); });
		
		$('#bookInfo p').slideUp(400);
		$('.largeImg').slideDown(500);
		$('.medImg').slideUp(400);
		
		readyToClose();
	});
}

//display list itemes
function getLibraryItems(cat,character) {
	
	$('#rightContent').css("min-height",$('#rightContent').height());
	$('.libList').css('background','#ffffff').fadeOut(400, function() {
		if(character == undefined) {
			var params = {'category': cat};
		} else {
			var params = {'category': cat, 'character': character};
			
			$('.alphabet .chars .active').removeClass('active').addClass('inactive');
			$('.alphabet .chars #alphabetNavLetter'+character).removeClass('inactive').addClass('active');	
			//update swf letter
			sendToActionScript(character);
		}
		
		$.get('../pages/functions/getPubItems.php', params, function(data) {
			$('.libList').html(data).css('background','#ffffff').fadeIn(400,function() {
				$('a.bookThumb img').bind("mouseover", function(data) {
					//show red bar
					var thumbLeft = $(this).offset().left;
					var thumbTop = $(this).offset().top;
					var thumbHeight = $(this).height();
					var thumbWidth = $(this).width();
					$('.hide').hide();
					$('#redHooverBar').css({position:'absolute',top:thumbTop+thumbHeight-3,left:thumbLeft,width:thumbWidth}).show();
				});
				$('a.bookThumb img').bind("mouseout", function(data) {
					$('#redHooverBar').hide();
				});
			});			
		});
	});
}