$(function(){


var options_t = {
        width: "fill",
        height: "auto", //height options are :
        autoUpdate : true

};

$('#Overlay').css('opacity', 0.5);

$('#Overlay').height($(document).height());	

	

$('.ManagementTeam li').each(function(index){

	$(this).find('a').click(function(){

		$('#Overlay').fadeIn();							

		$('#DialogueBox').fadeIn();

		$('#DialogueContent').addClass('Profile');

		$('#DialogueContent').html($('.ManagementTeam .Profile').eq(index).html());

		return false;

	})

})



$('#DialogueBox').find('.CloseButton').click(function(){												   

		$('#Overlay').fadeOut();

		$('#DialogueBox').fadeOut();

		$("#DialogueBox").removeAttr("style");

})



$('#Overlay').click(function(){												   

		$('#Overlay').fadeOut();

		$('#DialogueBox').fadeOut();

		$("#DialogueBox").removeAttr("style");

})







$('.Awards a').each(function(index){

	$(this).click(function(){

		$('#Overlay').fadeIn();							

		$('#DialogueBox').fadeIn();

		$('#DialogueContent').addClass('Details');

		$('#DialogueContent').html($('.Awards .Details').eq(index).html());

		return false;

	})

})



$('#photos a').each(function(index){

	$(this).click(function(){

		var loadImage = new Image();

			loadImage.src = $(this).attr('href');

			var newImage = '';

				newImage = "<img src='"+ $(this).attr('href') +"' alt='' style='border:4px solid #000;' />";

			$('#DialogueContent').html(newImage);

			

			loadImage.onload  = function(){	

			

			$('#Loader').fadeOut();

			

				var imageWidth = loadImage.width;

				var imageLeftmargin = -loadImage.width/2;

		

				if(imageWidth === 0){

					$('#DialogueBox').css({ 'text-align' : 'center' });

				}else {			

					$('#DialogueBox').css({

						'text-align' : 'center',

						'width' : imageWidth,

						'margin-left' : imageLeftmargin

					});

				}

				

				if(loadImage.height > 600){

					$('#DialogueBox').css({ 'top' : '100px' });

				}

									

				$('#DialogueBox').fadeIn();

			}

			$('#Overlay').fadeIn();

			$('#Loader').fadeIn();

			

		return false;

	})

})



/* Form scripting */

$('#suckerfishnav').find('>li:last').addClass('ContactNav');

	if($("#frm-contact").size()>0)

	{

		var $acholder = $("#ac-holder");

		$("input[name='isHolder']").click(function(){			

			if($(this).val() == "Yes")

			{

				if($acholder.hasClass("hidden")) //if div is hidden

				{

				//show div and remove class hidden				

				$acholder.removeClass("hidden").addClass("visible-sec");

				}

			}

			else

			{

				

				if($acholder.hasClass("hidden") == false) //if div is showing

				{

					//hide div and add class hidden to it

					$acholder.addClass("hidden");

				}

			}

		});

		

		$("input[name='contactType']").click(function(){

			switch ($(this).val())

			{

				case "Complaint":

					if($("#complaint").hasClass("hidden"))

					{

						$("#toc > div ").addClass("hidden");

						$("#complaint").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;

				

				case "Feedback":

					if($("#feedback").hasClass("hidden"))

					{

						$("#toc > div ").addClass("hidden");

						$("#feedback").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;

				

				case "Inquiry":

					if($("#inquiry").hasClass("hidden"))

					{

						$("#toc > div ").addClass("hidden");

						$("#inquiry").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;

				

				case "Job Application":

					if($("#job").hasClass("hidden"))

					{

						$("#toc > div ").addClass("hidden");

						$("#job").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;

			}

		});

		

		//complaint about - choices

		$("input[name='cAbout']").click(function(){

			switch ($(this).val())

			{

				case "Product":

					if($("#complaint .product").hasClass("hidden"))

					{

						$("#complaint > div ").addClass("hidden");

						$("#complaint .product").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;



				case "Service":

					if($("#complaint .service").hasClass("hidden"))

					{

						$("#complaint > div ").addClass("hidden");

						$("#complaint .service").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;



				case "Person":

					if($("#complaint .person").hasClass("hidden"))

					{

						$("#complaint > div ").addClass("hidden");

						$("#complaint .person").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;



				case "Other":

					if($("#complaint .other").hasClass("hidden"))

					{

						$("#complaint > div ").addClass("hidden");

						$("#complaint .other").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;

			}

		});

		//feedback - sections using dd

		$("#dd-feedback").change(function(){

			switch ($(this).val())

			{

				case "fabout":

					if($("#feedback .fb-about").hasClass("hidden"))

					{

						$("#feedback > div ").addClass("hidden");

						$("#feedback .fb-about").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;



				case "fbStaff":

					if($("#feedback .fb-staff").hasClass("hidden"))

					{

						$("#feedback > div ").addClass("hidden");

						$("#feedback .fb-staff").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;



				case "recommand":

					if($("#feedback .what-recomand").hasClass("hidden"))

					{

						$("#feedback > div ").addClass("hidden");

						$("#feedback .what-recomand").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;

			}

		});

		//feedback - sections

		/*

		$("input[name='fsection']").click(function(){

			switch ($(this).val())

			{

				case "fabout":

					if($("#feedback .fb-about").hasClass("hidden"))

					{

						$("#feedback > div ").addClass("hidden");

						$("#feedback .fb-about").removeClass("hidden");

					}

				break;



				case "fbStaff":

					if($("#feedback .fb-staff").hasClass("hidden"))

					{

						$("#feedback > div ").addClass("hidden");

						$("#feedback .fb-staff").removeClass("hidden");

					}

				break;



				case "recommand":

					if($("#feedback .what-recomand").hasClass("hidden"))

					{

						$("#feedback > div ").addClass("hidden");

						$("#feedback .what-recomand").removeClass("hidden");

					}

				break;

			}

		});

		*/

		

		

		//fb-about - choices

		$("input[name='fabout']").click(function(){

			switch ($(this).val())

			{

				case "Product":

					if($(".fb-about .product").hasClass("hidden"))

					{

						$(".fb-about > div ").addClass("hidden");

						$(".fb-about .product").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;



				case "Service":

					if($(".fb-about .service").hasClass("hidden"))

					{

						$(".fb-about > div ").addClass("hidden");

						$(".fb-about .service").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;



				case "Features":

					if($(".fb-about .features").hasClass("hidden"))

					{

						$(".fb-about > div ").addClass("hidden");

						$(".fb-about .features").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;

				

				case "Other":

					if($(".fb-about .other").hasClass("hidden"))

					{

						$(".fb-about > div ").addClass("hidden");

						$(".fb-about .other").removeClass("hidden");

						//$(".fw").css("marginBottom","30px");

					}

				break;

			}

		});

		

		$("input[name='isReceive']").click(function(){

			switch ($(this).val())

			{	

				case "yes":

					$(this).closest(".fw").next(".hidden").removeClass("hidden");

					break;

				

				default:

					$(this).closest(".fw").next().addClass("hidden");

					

					

			}

		});

		

		

		$("input[name='isReceiveType']").click(function(){

			switch ($(this).val())

			{	

				case "postal":

					$(this).closest(".fw").next(".hidden").removeClass("hidden");

					break;



				default:

					$(this).closest(".fw").next().addClass("hidden");





			}

		});

		

		//dropdown change event to show other textbox

		$(".dl-other").change(function(){

			var ele = $(this).closest("div").find(".other");

			if($(this).val().toLowerCase() == "other")

			{

				

				if(ele.hasClass("hidden") == true)

				{

					ele.removeClass("hidden");

				}

			}

			else

			{

				ele.addClass("hidden");

			}

		});

		

	$("form").validity(function() {	

		//$(".required").require().match(/^[A-Za-z\W]+$/," No numbers allowed."); 

		//$(".required").require(); 

		//$(".txtonly").match(/^[A-Za-z\W]+$/," No numbers allowed.");		

	});



	} //form checking ends 





//search box - hint show hide

$("#s").focus(function(){

			//$().jquery; -- to get version of $ object

			$this = $(this);

			var sval = $this.val();

			if(sval === "Search")

			{

				$this.val("");

			}

		}).blur(function(){

		$this = $(this);

			var sval = $this.val();

			if(sval.length === 0)

			{

				$this.val("Search");

			}

		});


		// UNB Insurance renewal form validation Script
		// use jquery validity: http://validity.thatscaptaintoyou.com/Demos/index.htm#Equal
		$(function() {
			$("#renew").validity(function() {
				$("#fname") 
				.require("Name is required");
				
				$("#address")                      
				.require();                          
				
				$("#postcode")                      
				.require();                          
				
				$("#email")                      
				.require("valid email address required")
                .match("email");
                          
				
				//Email confirmation
				$("#confirmemail, #email").require("this is required").match("email").assert(($("#email").val() == $("#confirmemail").val()),"mail and confirm email should match");
                          
				
				$("#mobile")                      
				.require(); 
				
				$("#landline")                      
				.require();                          
				
				//check if checkbox is checked
				//$("#chk_motor, #chk_home, #chk_landlord").assert($("input:checked").size() != 0,"Choose Atleast one Insurance.");
				var error = false;
				
				if($("#chk_motor").is(":checked") == false && $("#chk_home").is(":checked") == false && $("#chk_landlord").is(":checked") == false)
				{
					//$.validity.outputs.label.raise($("#chk_motor"),"atleast one option should be selected");
					return false;
				}
				else
				{
					//get all checkboxes which are checked
					//each loop
					 // if user one of the checkbox he has to be select its corespondence date.
					if($('#mmonth option:selected').text() == 0 && $("#chk_motor").is(":checked") == true)
					{
						$.validity.outputs.label.raise($("#mmonth"),"please select date");
						return false;
					}
					
					else if($('#hmonth option:selected').text() == 0 && $("#chk_home").is(":checked") == true)
					{
						$.validity.outputs.label.raise($("#hmonth"),"please select date");
						return false;
					}
					
					else if($('#lmonth option:selected').text() == 0 && $("#chk_landlord").is(":checked") == true)
					{
						$.validity.outputs.label.raise($("#lmonth"),"please select date");
						return false;
					}
					else {
						return true;
						}
				}
				
				
				//$.validity.outputs.label.raise($("#chk_home"),"najam");
				
				//.assert($("#chk_motor").find("input:checked").size() != 0,"mail and confirm email should match");
			});


			$("#mmonth").change(function() {
				if($('#mmonth option:selected').text() != 0){
					$('input[name=chk_motor]').attr('checked', true);
					} else {
						$('input[name=chk_motor]').attr('checked', false);
						}
			});
			
			$("#hmonth").change(function() {
				if($('#hmonth option:selected').text() != 0){
					$('input[name=chk_home]').attr('checked', true);
					} else {
						$('input[name=chk_home]').attr('checked', false);
						}
			});


			$("#hmonth_c").change(function() {
				if($('#hmonth_c option:selected').text() != 0){
					$('input[name=chk_home_c]').attr('checked', true);
					} else {
						$('input[name=chk_home_c]').attr('checked', false);
						}
			});

			
			$("#lmonth").change(function() {
				if($('#lmonth option:selected').text() != 0){
					$('input[name=chk_landlord]').attr('checked', true);
					} else {
						$('input[name=chk_landlord]').attr('checked', false);
						}
			});
			
			$("#chk_motor").click(function() {
				if($('#mmonth option:selected').text() == 0){
						$("#mmonth").val("JAN");
				}else {
						$("#mmonth").val("");
					}
				});
				
			$("#chk_home").click(function() {
				if($('#hmonth option:selected').text() == 0){
						$("#hmonth").val("JAN");
				}else {
						$("#hmonth").val("");
					}
				});
				
			
			$("#chk_home_c").click(function() {
				if($('#hmonth_c option:selected').text() == 0){
						$("#hmonth_c").val("JAN");
				}else {
						$("#hmonth_c").val("");
					}
				});


			$("#chk_landlord").click(function() {
				if($('#lmonth option:selected').text() == 0){
						$("#lmonth").val("JAN");
				} else {
						$("#lmonth").val("");
					}
				});

		
		});

			// Call me back service form
			$(function() {
			$("#cbms").validity(function() {
				$("#cmbname") 
				.require("name is required");

				$("#cmbphone") 
				.require('Please Enter Phone Number');
				//.require('Please Enter Phone #').match(/^\d{3}-\d{3}-\d{4}$/, "Phone # must be formatted as ###-###-####");

				})
			});


		$('.disclaimer').click(function(){
			//alert('working');
			window.close();
		});		

		$(".disclaimerWindow").click(function(event){
			window.open(this.href,	'Continue_to_Application','resizable=no,scrollbars=yes,width=1009,height=640');
			return false;
			
		});


}); //jquery ends


