function LoginFilled (usr, pwd) {
	var valid = true;
	if (!usr || !pwd) {
		alert("Please enter both your e-mail and password");
		valid = false;
	} else {
		document.mainlogin_form.submit_login.value = "logging in...";
		//disable submit button
		if (document.all||document.getElementById){
			for (i=0;i<document.mainlogin_form.length;i++){
				var tempobj=document.mainlogin_form.elements[i]
				if(tempobj.type.toLowerCase()=="submit"){
					tempobj.disabled=true;
				}
			}
		}
	}
	return valid;
}

function searchButton() {
	//disable submit button
	document.search_form.submit_search.value = "searching...";
	//disable submit button
	if (document.all||document.getElementById){
		for (i=0;i<document.search_form.length;i++){
			var tempobj=document.search_form.elements[i]
			if(tempobj.type.toLowerCase()=="submit"){
				tempobj.disabled=true;
			}
		}
	}
	return true;
}


	function hideAll() {
		$('#link-saveselection-close').hide();
		$('#link-addselection-close').hide();
		$('#bookmark-saveselection').hide();
		$('#bookmark-addselection').hide();
		$('#link-saveselection-open').show();
		$('#link-addselection-open').show();	
	}

	function showRequest(formData, jqForm, options) { 
	var queryString = $.param(formData); 
	return true; 
	} 
	function showResponse(responseText, statusText)  {  
	} 
	$.fn.clearForm = function() {
	  return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
		  return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
		  this.value = '';
		else if (type == 'checkbox' || type == 'radio')
		  this.checked = false;
		else if (tag == 'select')
		  this.selectedIndex = -1;
	  });
	};	   

	//function to show search bar
	function showSearch(){
		if($('#search-form-container-hide-div').css("opacity") == 0){
			$('#search-form-container-hide-div').animate({opacity: "1.0", top: "-20"}, 700);
			if($('#container-padding-loggedin').length == 0 && $('#container-padding-search').length > 0){
			//slide main area down if searchbar comes down
				$('#container-padding-search').animate({height: "60px"}, 700);
			}
		}	
	}//end function
	

	function lastPostFunc(){
		if($(".container-search-results:last").attr("id") != "search-end" && $(".container-search-results").length > 0){
			//alert("doc height:"+$(document).height()+"; window height:"+$(window).height()+"; scrollTop"+$(window).scrollTop()+";");

			$(".container-pagenumbers").hide();
			$('#lastPostsLoader').html('<img src="images/bigLoader.gif" width=\"100\" height=\"100\" />');
			$.post("search-more.php?lvl=search&searchParams=" + $(".container-search-results:last").attr("id"),     
			function(data){
				if (data != "") {
				$(".container-search-results:last").after(data);            
				}
				$('#lastPostsLoader').empty();
			});
		}
	}
	
	var timingSlideName = 3000;
	function funcSlideNames(stepNo){
		if(!stepNo) { 
			//If the argument is not there, create a new variable with that name.
			var stepNo = 1;
		}	
		switch(stepNo){
			case 1:
				$('#slideshow_nav_1').css('background-position', '-5px 0');
				stepNo = (stepNo * 1) + 1;
				setTimeout("funcSlideNames("+stepNo+")",timingSlideName);
				break;
			case 2:
				$('#slideshow_nav_1').css('background-position', '-198px 0');
				stepNo = (stepNo * 1) + 1;
				setTimeout("funcSlideNames("+stepNo+")",timingSlideName);
				break;
			case 3:
				$('#slideshow_nav_1').css('background-position', '-396px 0');
				stepNo = (stepNo * 1) + 1;
				setTimeout("funcSlideNames("+stepNo+")",timingSlideName);
				break;
			case 4:
				$('#slideshow_nav_1').css('background-position', '-594px 0');
				stepNo = (stepNo * 1) + 1;
				setTimeout("funcSlideNames("+stepNo+")",timingSlideName);
				break;
			case 5:
				$('#slideshow_nav_1').css('background-position', '-792px 0');
				stepNo = (stepNo * 1) + 1;
				setTimeout("funcSlideNames("+stepNo+")",timingSlideName);
				break;
			case 6:
				$('#slideshow_nav_1').css('background-position', '-990px 0');
				stepNo = 1;
				setTimeout("funcSlideNames("+stepNo+")",timingSlideName);
				break;
		}
	
	}
	

$(document).ready(function(){

	if($("#supersize img").length > 0){
		$.fn.supersized.options = {  
			startwidth: 1024,  
			startheight: 768,
			vertical_center: 1,
			slideshow: 0
		};
		$('#supersize').supersized();
	}
	
	
	//if($(".container-search-results").is(":visible") && $(".container-search-results:last").attr("id") != "search-end"){
		$(window).scroll(function(){
			if  (($(window).scrollTop() > $(document).height() - $(window).height() - 600) && $('#lastPostsLoader').is(':empty')){
			   lastPostFunc();
			}
		});
	//}
	
	
	$('#search-form-container-hide-div').css("opacity", 0);

	$('#nav-1 h2').mouseover(function(){
		showSearch();
	});
	$('#nav-1-active-nav h2').mouseover(function(){
		showSearch();
	});
	
	if($('#slideshow_nav_1').parent().parent().parent().parent().attr('id') == 'sub-nav-loggedout'){
		setTimeout("funcSlideNames()",timingSlideName);
	}
	
	
	/*
	$('#nav-2 h2').mouseover(function(){
		showSearch();
	});
	$('#nav-2-active-nav h2').mouseover(function(){
		showSearch();
	});
*/	
	
	$('#img-intro-1').delay(5000).fadeIn(2000, function(){
		$(this).delay(2500).hide(0,function(){
			$('#img-intro-2').show(0, function(){
				$('#container-col2').delay(2500).animate({opacity: "1.0"}, 1000);
			});
		});
	
	});
	$('#container-col1').mouseover(function(){
		$('#img-intro-2').hide();
		$('#img-intro-1').show();
	}).mouseout(function(){
		$('#img-intro-1').hide();
       	$('#img-intro-2').show();
    });;

	
	//menu dropdown IE redundancy - compensate for hover quasi-class
	$('#cssdropdown li.headlink').hover(
		function() { $('ul', this).css('display', 'block'); },
		function() { $('ul', this).css('display', 'none'); });
		
   

   if(document.form_selectselection){
		var options = { 
			target:        '#addselection_preview',
			beforeSubmit:  function() { 
				$('#addselection_preview').html('<img src=\"images/ajax-loader.gif\" style=\"padding-left:160px;padding-top:50px;padding-bottom:50px;\" />');

			}
		}; 
//		$('#form_selectselection').ajaxForm(options);
		/*
        $('#select_selectionRef').bind('onchange', function() {
            $('#form_selectselection').ajaxSubmit(options);
            return false; // <-- important!
        });		
		*/
        $('#select_selectionRef').change( function() {
            $('#form_selectselection').ajaxSubmit(options);
        });		
		
	}
		
   
	if(document.getElementById('client-logos')){
		$('#client-logos').cycle({
		timeout:       8000,
		speed:         2000
		});
	}
	if(document.getElementById('gallery')){
 		$('#gallery').galleryView({
			panel_width: 600,
			panel_height: 190,
			frame_width: 0,
			frame_height: 0,
			pause_on_hover: true, 
			show_filmstrip: false
		});  
	}
	
	//For @ sign on contact page
	if($('.atsign')){
		$('.atsign').html('@');
	}
	
	
	//-------FOR PAGE MODEL
	var thumbnail_min_opacity = 0.3;
	var thumbnail_max_opacity = 0.8;
	var thumbnail_time_fadein = 200;
	var thumbnail_time_fadeout = 600;
	$('.thumbnail_image').hover(function(){
			if(!($(this).hasClass("thumbnail_highlighted"))){
				$(this).stop().animate({opacity: thumbnail_max_opacity}, thumbnail_time_fadein); 
			}
		}, function(){
			if(!($(this).hasClass("thumbnail_highlighted"))){
				$(this).stop().animate({opacity: thumbnail_min_opacity}, thumbnail_time_fadeout); 
			}
	});
	$('.thumbnail_image a').click(function(e){
		e.preventDefault();
		var tmp_val = $(this).attr('rel');
		$('.mainimage_image').not("#"+tmp_val).addClass('display_none');
		$("#"+tmp_val).removeClass('display_none');
		
		$('.thumbnail_image').removeClass('thumbnail_highlighted').css('opacity', thumbnail_min_opacity);
		$(this).parent().addClass('thumbnail_highlighted').removeAttr('style');
	});
	
	$('#select_update_location_city').change(function(){
		if($('#form_update_location :input[name="orig_address_1"]').val() == $('#form_update_location :input[name="address_1"]').val() && $('#form_update_location :input[name="orig_address_2"]').val() == $('#form_update_location :input[name="address_2"]').val() && $('#form_update_location :input[name="orig_postCode"]').val() == $('#form_update_location :input[name="postCode"]').val()){
			var check_go = 'y';
			//confirm action
			var answer = confirm ("Are you sure you want to change their city?\nThis will delete their current address"); 
			if (answer){
				//do nothing
			} else {
				check_go = 'n';
			}
			if(check_go == 'y'){
				$('#form_update_location :input[name="clear_address"]').val('y');
				$(this).parent().parent().submit();
			}	
		
		}//check that all previous details are the same, therefore potentially need to delete them coz of change of location
	});

	
	
	
	//For the mybookmarked saved selections
	$('#selectionRef').change(function(){
		$('#form_loadselection').submit();
	});
	$('#selection_modelRef').change(function(){
		$('#selectionRef').removeAttr('selected').val('');
		$('#form_loadselection').submit();
	});
	
	
	
	//-------FOR LANDING PAGE
	$('.explain_option a').click(function(e){
		e.preventDefault();
		var tmp_val = $(this).attr('rel');
		if(tmp_val == 'open'){
			$(this).attr('rel', 'close');
			$(this).html('close explanation');
			$(this).parent().next().next().removeClass('display_none');
		} else {
			$(this).attr('rel', 'open');
			$(this).html('explain?');		
			$(this).parent().next().next().addClass('display_none');
		}
	});
	
	
   
});
