/******************* GALLERY HOMEPAGE START *******************/
var autoScroll = setInterval(function () {homeScroller();}, 4000);
function homeScroller(id){
    if(id){
        whichIndex = id - 1;
        clearInterval(autoScroll);
    }
    else{
        whichIndex = $('div#gallery-wrapper ul li[class=active]').index() + 1;
    }
    

    if(whichIndex == 5){
        whichIndex = 0;
    }

    whereMove = (whichIndex * 119) + 4;
	whichList = $('div#gallery-wrapper ul li');
	whichA = $('div#gallery-wrapper a');
    whichList.removeClass('active');

    $('div#gallery-wrapper > div#white-overlay').animate({'left':'+' + whereMove + 'px'}, 'fast', function() {
        whichList.eq(whichIndex).addClass('active');
        whichA.fadeOut(150);
        whichA.eq(whichIndex).fadeIn(250);
    });  
}

/******************* GALLERY HOMEPAGE END *******************/

/******************* STD POPUP FORM START *******************/
function show_form(call_subject, call_receive){
	window.scrollTo(0, 0);
	var docHeight = $(document.body).height();
	
	$('<div id="transparent-bg"></div>').appendTo('body');
	$('#transparent-bg').css({'width' : '100%', 'height' : docHeight});
	$('#transparent-bg').after('<div id="contact_form_wrapper"><img src="images/contact_form_close.gif" border="0" alt="" onclick="hide_form();" /><div id="contact_form_top"></div><div id="contact_form_bottom"><form action="mailform/lifewise.php" method="post" onsubmit="return checkCall();"><input name="subject" id="callback_subject" value="' + call_subject + '" type="hidden" /> <input name="recipient" id="callback_recipient" value="' + call_receive + '" type="hidden" /> <input name="redirect" value="/thankyou_form.html" type="hidden" /> <table id="contact_table" border="0" cellspacing="0" cellpadding="0" align="left"><tbody><tr><td width="130">Your Name</td><td width="205"><input type="text" id="call_name" name="your_name" class="contact_input" /></td><td valign="top">Query / Comments</td></tr><tr><td>Company Name</td><td><input type="text" name="company_name" class="contact_input" /></td><td rowspan="3"><textarea name="query" class="contact_textarea"></textarea></td></tr><tr><td>Telephone</td><td><input type="text" id="call_phone" name="phone_number" class="contact_input" /></td></tr><tr><td>Email</td><td><input type="text" id="call_email" name="your_email" class="contact_input" /></td></tr></tbody></table><br style="clear:both;"/><input name="submit" src="images/contact_form_submit.gif" style="margin-top:19px;" type="image" valign="top" align="right" /></form></div></div>');
}	
function hide_form(){
	$('#contact_form_wrapper').remove();
	$('#transparent-bg').remove();
}	
function checkCall(){
	if (document.getElementById('call_name').value == "") {alert("Your Name is required field");return false;}
	if (document.getElementById('call_phone').value == "") {alert("Telephone is required field");return false;}
	if (document.getElementById('call_email').value == "") {alert("Email address is required field");return false;}
}
/******************* STD POPUP FORM END *******************/

function validateRegistration(){
	if($('input.reg-box[name=CustomFields[12]]').val() == ''){alert('You need to enter your Full Name.'); return false;}
	if($('input.reg-box[name=email]').val() == ''){alert('You need to enter your Email Address.'); return false;}
	if (!(/^\w+([\'`\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test($('input.reg-box[name=email]').val()))){alert("Invalid Email Address format. Please re-enter."); return false;}
	if($('select.reg-box[name=CustomFields[13]]').val() == ''){alert('You need to choose your County.'); return false;}
	$('form#registration-form').submit();
}

$(document).ready(function() {
    $('div#gallery-wrapper').hover(
        function () {clearInterval(autoScroll);}, 
        function () {autoScroll = setInterval(function () {homeScroller();}, 4000);}
    );

    

/******************* SECTION BOXES HOMEPAGE START *******************/
    $('div.section-boxes-wrapper > div.section-box > div.vertical-tabs-wrapper > a.link-list').mouseover(function(){
		if($(this).css('background-color') != 'rgb(244, 244, 246)' && $(this).css('background-color') != '#f4f4f6'){
			whereFind = $(this).parent();
			whereFindImg = whereFind.find('img');
			whereFind.find('a').css('background-color','#ffffff');
			$(this).css('background-color','#f4f4f6');
			whereFindImg.stop(true, true).fadeOut(150);
			whereFindImg.eq($(this).index() - 1).stop(true, true).fadeIn(250);
		}
    });

/******************* SECTION BOXES HOMEPAGE END *******************/ 

/******************* TOP NAVIGATION START *******************/
/*
    $('div#top-nav').hover(
        function(){
            $(this).css('background-position','0px -30px')
            $('div#top-nav ul').stop(true,true).slideDown('fast'); },
        function(){
            $(this).css('background-position','0px 0px')
            $('div#top-nav ul').stop(true,true).slideUp('fast');
    });
*/

    $('div#top-nav').hover(
        function(){
            $(this).css('background-position','0px -30px')
            $('div#top-nav ul').stop(true,true).toggle(); },
        function(){
            $(this).css('background-position','0px 0px')
            $('div#top-nav ul').stop(true,true).toggle();
    });
/******************* TOP NAVIGATION END *******************/     

// CHECK IF THE ELEMENTS EXIST
if($('div#sml-carousel-wrapper').length > 0){

	/***************************** START CAROUSEL SCRIPT  SMALL ************************************/
		$('#sml-carousel a:first').before($('#sml-carousel a:last')); 
		$('#sml-right-scroll').click(function(){
			var item_width = $('#sml-carousel a').outerWidth() + 44;
			var left_indent = parseInt($('#sml-carousel').css('left')) - item_width;
			$('#sml-carousel:not(:animated)').animate({'left' : left_indent},500,function(){    
				$('#sml-carousel a:last').after($('#sml-carousel a:first')); 
				$('#sml-carousel').css({'left' : '-121px'});
			}); 
		});
		
		$('#sml-left-scroll').click(function(){        
			var item_width = $('#sml-carousel a').outerWidth() + 44;
			var left_indent = parseInt($('#sml-carousel').css('left')) + item_width;
			$('#sml-carousel:not(:animated)').animate({'left' : left_indent},500,function(){    
				$('#sml-carousel a:first').before($('#sml-carousel a:last')); 
				$('#sml-carousel').css({'left' : '-121px'});
			});          
		});
		// THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
		sml_slide_interval = setInterval(function () {$('#sml-right-scroll').trigger('click'); }, 2000);
		
		$("#sml-carousel-wrapper").hover(
			function () {clearInterval(sml_slide_interval);}, 
			function () {sml_slide_interval = setInterval(function () {$('#sml-right-scroll').trigger('click'); }, 2000);}
		);
	/***************************** END CAROUSEL SCRIPT  SMALL ************************************/
}

});
