/** BEGIN global varibales **/
var obj = null;
var proj = 0;
var color = null;
var interval = null;
var navVisible = false;
/** END global variables **/

/** BEGIN user-defined functions **/
function commentFilter() {
	if (jQuery('#urlfield').attr('value')==commentUrl) {
		jQuery('#urlfield').attr({ 'value' : '' });
		return false;
	}
}
function checkHover() {
	if (obj) obj.find('ul').fadeOut('fast');
}
function textSlideIn(proj) {
	if (navVisible) {
		jQuery('.next').stop().animate({ 'top' : '140' });
		jQuery('.prev').stop().animate({ 'top' : '140' });
	}
	jQuery('ul.text').children('li:eq('+proj+')').animate({ right: "-1px" }, 700);
}
function textSlideOut(proj) {
	if (navVisible) {
		jQuery('.next').stop().animate({ 'top' : '348' });
		jQuery('.prev').stop().animate({ 'top' : '348' });
	}
	jQuery('ul.text').children('li:eq('+proj+')').animate({ right: "-251px" }, 700);
}
function photoFadeIn(proj) {
	jQuery('ul.photo').children('li:eq('+proj+')').fadeIn(700);
}
function photoFadeOut(proj) {
	jQuery('ul.photo').children('li:eq('+proj+')').fadeOut(700);
}
function photoPutBehind(proj) {
	jQuery('ul.photo').children('li:eq('+proj+')').css('z-index', 0);
}
function moveSlide(where) {
	// Slide exit
	jQuery('ul.photo').children('li:eq('+proj+')').css("z-index", 2);
	setTimeout('photoFadeOut('+proj+')', 1000);
	setTimeout('photoPutBehind('+proj+')', 1500);
	textSlideOut(proj);
	// Increment and checking
	if (where=='next') proj++;
	else if (where=='prev') proj--;
	if (where=='next') { 
		var i = jQuery('ul.text li').size() - 1;
		if (proj>i) proj = 0;
	}
	else if (where=='prev') {
		if (proj<0) proj = jQuery('ul.text li').size() - 1;
	}
	// Slide entrance
	setTimeout('photoFadeIn('+proj+')', 1000);		
	setTimeout('textSlideIn('+proj+')', 1500);
}
function selectTab(tabID, index) {
	jQuery('#' + tabID + ' ul.tabs li a').removeClass('here');
	jQuery('#' + tabID + ' ul.tabs li:eq(' + index + ') a').addClass('here');
	jQuery('#' + tabID + ' .b div').css('display', 'none');
	jQuery('#' + tabID + ' .b div:eq(' + index + ')').css('display', 'block');
}

function addTab(tabID) {
	jQuery('#' + tabID).addClass('box');
	jQuery('#' + tabID).html('<div class="b">' + jQuery('#' + tabID).html() + '</div>');
	jQuery('#' + tabID + ' ul li').click(function() {
		jQuery('#' + tabID + ' ul li a').removeClass('here');
		jQuery(this).children('a').addClass('here');
		var index = jQuery('#' + tabID + ' ul li').index(jQuery(this));
		jQuery('#' + tabID + ' .b').children('div').css('display', 'none');
		jQuery('#' + tabID + ' .b').children('div:eq(' + index + ')').css('display', 'block');
		return false;
	});
	selectTab(tabID, 0);
}
/** END user-defined functions **/

document.write('<link rel="stylesheet" type="text/css" href="' + cssdir + 'javascript.css" />');
jQuery(window).load(function() {
	jQuery("#wrapper").css({ "display" : "block" });
	jQuery("#loader").remove();
	jQuery('.next').stop().animate({ 'top' : '348' });
	jQuery('.prev').stop().animate({ 'top' : '348' });
});

/** BEGIN jQuery actions **/
jQuery(function() {
	
	if (hideLoading) jQuery("body").append('<div id="loader">'+loadingMessage+'</div>'); else jQuery("#wrapper").css({ "display" : "block" });
	
	/** begin featured content **/
	if (autoSlide) interval = setInterval('moveSlide("next")', autoSlideSecs*1000);
	jQuery('.next').click(function() {
		clearInterval(interval);
		moveSlide('next');
		if (autoSlide) interval = setInterval('moveSlide("next")', autoSlideSecs*1000);
		return false;
	});
	jQuery('.prev').click(function() {
		clearInterval(interval);
		moveSlide('prev');
		if (autoSlide) interval = setInterval('moveSlide("next")', autoSlideSecs*1000);
		return false;
	});
	jQuery('.featured').hover(
		function() {
			navVisible = true;
			jQuery('.next').stop().animate({ 'top' : '140' });
			jQuery('.prev').stop().animate({ 'top' : '140' });
		},
		function() {
			navVisible = false;
			jQuery('.next').stop().animate({ 'top' : '348' });
			jQuery('.prev').stop().animate({ 'top' : '348' });
		}
	);
	/** end featured content **/
	
	/** begin submenu **/
	jQuery('#header ul > li').hover(
		function() {
			if (obj) {
				obj.children('ul:first')
					.css('display', 'none');
				obj = null;
			}
			jQuery(this).children('ul:first')
				.fadeIn();
		},
		function() {
			obj = jQuery(this);
			setTimeout("checkHover()", 1000);
		}
	);
	/** end submenu **/
	
	/** begin search form **/
	jQuery('#s').attr({ 'value' : searchDefault });
	jQuery('#s').focus(function() {
		var temp = jQuery(this).attr('value');
		color = jQuery(this).css('color');
		jQuery(this).css({ 'color' : inputColor });
		if (temp==searchDefault)
			jQuery(this).attr({ 'value' : '' })
	});
	jQuery('#s').blur(function() {
		if (jQuery(this).attr('value')=='') {
			jQuery(this).attr({ 'value' : searchDefault });
		}
		jQuery(this).css({ 'color' : color });
	});
	/** end search form **/	
	
	/** BEGIN comment form **/
	
		/** begin name **/
		if (jQuery('#userfield').attr('value')=='')
			jQuery('#userfield').attr({ 'value' : commentName });
		jQuery('#userfield').focus(function() {
			var temp = jQuery(this).attr('value');
			color = jQuery(this).css('color');
			jQuery(this).css({ 'color' : inputColor });
			if (temp==commentName)
				jQuery(this).attr({ 'value' : '' })
		});
		jQuery('#userfield').blur(function() {
			if (jQuery(this).attr('value')=='') {
				jQuery(this).attr({ 'value' : commentName });
			}
			jQuery(this).css({ 'color' : color });
		});
		/** end name **/
		
		/** begin email **/
		if (jQuery('#emailfield').attr('value')=='')
			jQuery('#emailfield').attr({ 'value' : commentEmail });
		jQuery('#emailfield').focus(function() {
			var temp = jQuery(this).attr('value');
			color = jQuery(this).css('color');
			jQuery(this).css({ 'color' : inputColor });
			if (temp==commentEmail)
				jQuery(this).attr({ 'value' : '' })
		});
		jQuery('#emailfield').blur(function() {
			if (jQuery(this).attr('value')=='') {
				jQuery(this).attr({ 'value' : commentEmail });
			}
			jQuery(this).css({ 'color' : color });
		});
		/** end email **/
		
		/** begin url **/
		if (jQuery('#urlfield').attr('value')=='')
			jQuery('#urlfield').attr({ 'value' : commentUrl });
		jQuery('#urlfield').focus(function() {
			var temp = jQuery(this).attr('value');
			color = jQuery(this).css('color');
			jQuery(this).css({ 'color' : inputColor });
			if (temp==commentUrl)
				jQuery(this).attr({ 'value' : '' })
		});
		jQuery('#urlfield').blur(function() {
			if (jQuery(this).attr('value')=='') {
				jQuery(this).attr({ 'value' : commentUrl });
			}
			jQuery(this).css({ 'color' : color });
		});
		/** end url **/
		
	/** END comment form **/
	
	/** begin youtube video **/
	var videoEmbedd = "<object width=\""+videoWidth+"\" height=\""+videoHeight+"\"><param name=\"movie\" value=\"http://www.youtube.com/v/"+youtubeID+"&amp;hl=en&amp;fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/"+youtubeID+"&amp;hl=en&amp;fs=1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\""+videoWidth+"\" height=\""+videoHeight+"\"></embed></object>";
	jQuery('#youtube').html(videoEmbedd);
	/** end youtube video **/
	
	/** begin lightbox post images **/
	if (lightbox) jQuery('#content .span .content a img').parent().attr({ 'rel' : 'lightbox[blah]' });
	/** end lightbox post images **/
	
});
/** END jQuery actions **/
