$(function() {
	// homepage
	$('#emailAddressInp').defaultvalue('Your Email Address');
	// homepage slider
	$.preload('#homeSlide div img', {
		onFinish: playHome
	});
	$('#control1').css('cursor','pointer').click(function() { actionCall(1) });
	$('#control2').css('cursor','pointer').click(function() { actionCall(2) });
	$('#control3').css('cursor','pointer').click(function() { actionCall(3) });
	$('#control4').css('cursor','pointer').click(function() { actionCall(4) });
	//$('#control5').css('cursor','pointer').click(function() { actionCall(5) });
	
	// news slider
	// calculate total width of list by adding all list item widths
	var wid = 0;
	$('#newsfeed ul li').each(function (i) { wid = wid + $(this).innerWidth(); });
	$('#newsfeed ul').width(wid);
	// trigger news slide
	setInterval('moveNews(' + index + ')', newsDelay);
});
// you can change these values
var delay = 10000;
var playCountMax = 2
// do not change these values
var playCount = 0;
var timeOne = 0;
var timeTwo = 0;
var timeThree = 0;
var timeFour = 0;
var timeFive = 0;
var timeNext = 0;
function playHome() {
	$('#homeSlide').css('background-image','none');
	actionCall(1);
}
function show1() {
	playCount++;
	$('#slide4').fadeOut('slow');
	$('#control4').removeClass('active');
	$('#slide1').fadeIn('slow', function() { timeOne = setTimeout("show1()",delay); });
	$('#control1').addClass('active');
}

function show2() {
	if (playCount <= playCountMax) {
		$('#slide1').fadeOut('slow');
		$('#control1').removeClass('active');
		$('#slide2').fadeIn('slow', function() { timeTwo = setTimeout("show3()",delay); });
		$('#control2').addClass('active');
	}
}

function show3() {
	if (playCount <= playCountMax) {
		$('#slide2').fadeOut('slow');
		$('#control2').removeClass('active');
		$('#slide3').fadeIn('slow', function() { timeThree = setTimeout("show4()",delay); });
		$('#control3').addClass('active');
	}
}
function show4() {
	if (playCount <= playCountMax) {
		$('#slide3').fadeOut('slow');
		$('#control3').removeClass('active');
		$('#slide4').fadeIn('slow', function() { timeFour = setTimeout("show1()",delay); });
		$('#control4').addClass('active');
	}
}
function show5() {
	if (playCount <= playCountMax) {
		$('#slide4').fadeOut('slow');
		$('#control4').removeClass('active');
		$('#slide5').fadeIn('slow', function() { timeFour = setTimeout("show1()",delay); });
		$('#control5').addClass('active');
	}
}
function actionCall(sec) {
	clearTimeout(timeNext);
	if (sec <= 4) {
		var nextSec = sec + 1;
	} else {
		var nextSec = 1;
	}
	clearTimeout(timeOne);
	clearTimeout(timeTwo);
	clearTimeout(timeThree);
	clearTimeout(timeFour);
	//clearTimeout(timeFive);
	$('#homeSlide div').fadeOut('fast');
	$('#controls li').removeClass('active');
	$('#slide' + sec + '').fadeIn('slow');
	$('#control' + sec + '').addClass('active');
	// continuous play control, comment for no autoplay
	if (playCount <= playCountMax) {
		timeNext = setTimeout("show" + nextSec + "()",delay);
	}
}
// delay between news items scrolling
var newsDelay = 5000;
// do not change below here
var index = 0;
function moveNews(index) {
	if (index <= $('#newsfeed ul li').size()) {
		$('#newsfeed ul li:eq(' + index + ')').clone().appendTo('#newsfeed ul');
		$('#newsfeed ul li:eq(' + index + ')').hide('slow', function() { $(this).remove() });
		index++
	}
}
/**
 * jQuery Default Value Plugin v1.0
 * Progressive enhancement technique for inital input field values
 *
 * The MIT License
 * 
 * Copyright (c) 2007 Paul Campbell (pauljamescampbell.co.uk)
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @param		String
 * @return		Array
 */
(function(a){a.fn.defaultvalue=function(){var d=this;var b=arguments;var e=0;return(d.each(function(){var c=a(this);var f=b[e++];c.val(f).focus(function(){if(c.val()==f){c.val("")}c.blur(function(){if(c.val()==""){c.val(f)}})})}))}})(jQuery);
