/**
 * Cookie object (data storage for font resizer)
 */
var cookie = {
	set: function(name, value, days) {
		var expires = '';
		if (days) {
			var date = new Date();
			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
			expires = '; expires=' + date.toGMTString();
		}
		document.cookie = name + '=' + value + expires + '; path=/';
	},
	get: function(name) {
		var nameEQ = name + '=';
		var ca = document.cookie.split(';');
		for (var i=0; i < ca.length; i++) {
			var c = ca[i];
			while (c.charAt(0) == ' ') c = c.substring(1, c.length);
			if (c.indexOf(nameEQ) > -1) return c.substring(nameEQ.length, c.length);
		}
		return null;
	}
};

/**
 * Font Resizer object
 */
var fontResizer = {
	fontSize: '62.5%',
	fontSizes: ['62.5%', '75%', '80%'],
	init: function() {
		this.readFromCookie();
	},
	readFromCookie: function() {
		var cookieFontSize = cookie.get('fontSize');
		if (cookieFontSize != null && cookieFontSize != '' && $.inArray(cookieFontSize, this.fontSizes)) {
			this.fontSize = cookieFontSize;
			$('body').css('fontSize', this.fontSize);
		}
	},
	enlarge: function() {
		this.setSize(1);
	},
	shrink: function() {
		this.setSize(-1);
	},
	setSize: function(inc) {
		var currentIndex = $.inArray(this.fontSize, this.fontSizes);
		if (this.fontSizes[currentIndex + inc] != null) {
			var newFontSize = this.fontSizes[currentIndex + inc];
			this.fontSize = newFontSize;
			$('body').css('fontSize', newFontSize);
		}
		cookie.set('fontSize', this.fontSize, 30);
	}
};

$(document).ready(function() {
	
	Cufon.replace('span.banner-text', {textShadow: '#000 1px 1px, #A69992 1px 1px'});
	Cufon.replace('span.banner-title', {textShadow: '#000 1px 1px, #A69992 1px 1px'});
	
	$.browser.msie6 = $.browser.msie && parseInt($.browser.version) == 6 && !window["XMLHttpRequest"];
	// Add accordion to the login box
	$('ul.login').accordion({
		'animated': false,
		'header': 'li > a',
		alwaysOpen: false,
		active: '.selected',
		autoheight: false
	});

	// Add accordion to the service menu
	$('ul.service > li > a').bind('click', function(evt) {
		if ($(evt.target).attr('href') != '#') {
			evt.stopPropagation();
		}
	});
	$('ul.service').accordion({'animated':false, 'header':'li > a'});

	// Pagination
	$('.itemsPage ul').bind('mouseenter', function(evt) {
		evt.preventDefault();
		$('li', $(this)).show();
	});
	$('.itemsPage ul').bind('mouseleave', function(evt) {
		evt.preventDefault();
		$('li', $(this)).not('.selected').hide();
	});

	// Content background image scaling
	if($('img.contentBack').length > 0) {
		var height = $('#middle').height();
		$('img.contentBack').attr('height', height);
	}

	// Search ISBN tooltip
	$('.btnExclamation a').bind('mouseover', function(evt) {
		$('.tooltipInfo').css({'left':evt.clientX + 5, 'top':evt.clientY + 5}).show();
	}).bind('mouseout', function(evt) {
		$('.tooltipInfo').hide();
	});

	// Bind Font Resizer
	fontResizer.init();
	$('.text_smaller').bind('click', function(evt) {
		evt.preventDefault();
		fontResizer.shrink();
	});
	$('.text_larger').bind('click', function(evt) {
		evt.preventDefault();
		fontResizer.enlarge();
	});
	
	Cufon.now();
	$(window).unload(function(){
		$("canvas, span.cufon").remove();
	});
});


$('iframe').load(function()
	{
		// Set inline style to equal the body height of the iframed content.
		//alert(this.contentWindow.document.body.offsetHeight);
		//alert(this.contentWindow.document.body.scrollHeight);
		//this.style.height = (this.contentWindow.document.body.offsetHeight + 30) + 'px';
		var iframeHeight = this.contentWindow.document.body.scrollHeight;
		//if(navigator.appName != "Microsoft Internet Explorer")
			iframeHeight = iframeHeight + 20;
		if (iframeHeight < 300)
			iframeHeight = 300;
		
		this.style.height = "" + iframeHeight + "px";
	}
);
	
