
// When the document is ready
$(document).ready(function() {
	// Compose path to flash movie:
	var flashMovieSource = JQueryBaseHref + 'flash/header.swf';
	if(typeof headerXmlSource != 'undefined') {
		flashMovieSource += '?def=' + headerXmlSource;
	}
	
	// Show flash in banner:
	/**/
	if(navigator.userAgent.indexOf("Win") != -1) {
		document.getElementById('banner').innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="900" height="206" id="site" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" /><param name="movie" value="'+ flashMovieSource +'" /><param name="quality" value="high" /><param name="bgcolor" value="#FFFFFF" /><embed src="'+ flashMovieSource +'" quality="high" bgcolor="#FFFFFF" width="900" height="206" name="site" align="middle" allowScriptAccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	} else {
		$('#banner').flash({
			src : flashMovieSource,
			width : 900,
			height : 206,
			wmode : 'transparent'
		});
	}
	
	// Do carousel
	$("#carousel").fadeIn(300).jcarousel();
	
	// Flashzine links
	$("a.flashzine").click(function() {
		var w = 927;
		var h = 672;
		
		var winl = parseInt((screen.width-w)/2);
		var wint = parseInt((screen.height-h)/2);
		if (winl < 0) winl = 0;
		if (wint < 0) wint = 0;
		
		zinepop = window.open(JQueryBaseHref + 'flashzine/flashzine.php?fn=' + $(this).attr('href').substr(1, $(this).attr('href').length) + '&title=' + $(this).attr('title') + '&nocache=gksjdlfg&uri=' + JQueryBaseHref, 'flashzine', 'toolbar=0,width=927,height=672,left='+winl+',top='+wint+',resizable=false');
		zinepop.focus();
		return false;
	});
	
	// Create lightbox interface out of all links that carry the 
	// "lightbox" class:
	$('a.fancybox').fancybox({
		'titlePosition' : 'over',
		'overlayColor'	: '#000000'
	});
	
	$(".youtube").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'overlayColor'	: '#000000',
			'title'			: this.title,
			'width'			: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
				 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

		return false;
	});
	
	// Do focus/blur of input fields
	$('input[@type=text], textarea').focus(function() {
		showInputFrame($(this));
	});
	
	$('input[@type=text], textarea').blur(function() {
		hideInputFrame($(this));
	});
});

function showInputFrame($inputControl) {
	// Local variables
	var offset, tWidth, tHeight;
	
	// Get the input control's position on the page:
	offset = $inputControl.offset();
	
	// Target width + height of the frame:
	tWidth  = $inputControl.width();
	tHeight = $inputControl.height() + 6;
	
	// Create frame, if not existing yet:
	if(! document.getElementById('inputControlFrame')) {
		//$('body').append('<div id="inputControlFrame" style="display: none"></div>');
		$('body').append('<div id="inputControlFrame"></div>');
		$('#inputControlFrame').css({
			width: tWidth + 'px',
			height: tHeight + 'px',
			position: 'absolute',
			top: (offset.top - 20),
			left: offset.left,
			border: '2px solid #0a65b1',
			opacity: 0
		});
	}
	
	// Stop any ongoing animation:
	$('#inputControlFrame').stop();
	
	// We animate the frame, adjusting position and size
	$('#inputControlFrame').animate({ 
        width : tWidth  + 'px',
        height : tHeight + 'px',
        top : offset.top,
        left : offset.left,
        opacity: 1
	}, 200);
}

function hideInputFrame($inputControl) {
	$('#inputControlFrame').stop();
	$('#inputControlFrame').fadeOut(500);
}

function openFlashzine(book, title, randomGetal, uri) {
	var w= 927;
	var h = 672;
	
	var winl = parseInt((screen.width-w)/2);
	var wint = parseInt((screen.height-h)/2);
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	
	zinepop = window.open('flashzine/flashzine.php?fn='+book+'&title='+title+'&nocache='+randomGetal+'&uri='+uri,'flashzine','toolbar=0,width=927,height=672,left='+winl+',top='+wint+',resizable=false');
	zinepop.focus();
}

