function JT_show(url,linkId,title) {
	$('#JT').remove();
	if(title == false) {
		title="&nbsp;";
	}
	var de = document.documentElement;
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var hasArea = w - getAbsoluteLeft(linkId);
	var clickElementy = getAbsoluteTop(linkId) - 3; //set y position

	// class=help, rel=width:20
	var params = new Array ();
	params['link'] = $('#'+linkId).attr('href');
	var rev = $('#'+linkId).attr('rel');
	if (rev) {
		rev = rev.split(':');
		if(rev.length > 1) {
			params['width'] = rel[1];
		} else {
			params['width'] = 250;
		}
	} else {
		params['width'] = 250;
	}

	if(params['link'] !== undefined) {
	//	$('#' + linkId).bind('click',function(){window.location = params['link']});
	//	$('#' + linkId).css('cursor','pointer');
	}

	if (hasArea>((params['width']*1)+75)) {
		var newbody = '<div id="JT" style="width:'+params['width']*1+'px;">';
		newbody+= '<div id="JT_arrow_left"></div>';
		newbody+= '<div id="JT_close_left">'+title+'</div>';
		newbody+= '<div id="JT_copy"><div class="JT_loader"></div></div>';
		newbody+= '</div>';
		$("body").append(newbody);//right side
		var arrowOffset = getElementWidth(linkId) + 11;
		var clickElementx = getAbsoluteLeft(linkId) + arrowOffset; //set x position
	} else {
		var newbody = '<div id="JT" style="width:'+params['width']*1+'px;">';
		newbody+= '<div id="JT_arrow_right" style="left:'+((params['width']*1)+0)+'px;"></div>';
		newbody+= '<div id="JT_close_right">'+title+'</div>';
		newbody+= '<div id="JT_copy"><div class="JT_loader"><div></div>';
		newbody+= '</div>'
		$("body").append(newbody);//left side
		var clickElementx = getAbsoluteLeft(linkId) - ((params['width']*1) + 15); //set x position
	}
	$('#JT').hide();
	$('#JT').css({
		left: clickElementx+"px", 
		top: clickElementy+"px"
	});
	$('#JT').fadeIn("fast",function(){
		$('#JT_copy').html($('#'+linkId+'-text').html());
	});
}
function getElementWidth(objectId) {
	var x = document.getElementById(objectId);
	return x.offsetWidth;
}


function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	var o = document.getElementById(objectId);
	oLeft = o.offsetLeft;				// Get left position from the parent object
	while(o.offsetParent!=null) {		// Parse the parent hierarchy up to the document element
		oParent = o.offsetParent;		// Get parent object reference
		oLeft += oParent.offsetLeft;	// Add parent left position
		o = oParent;
	}
	return oLeft;
}
function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	o = document.getElementById(objectId);
	oTop = o.offsetTop;					// Get top position from the parent object
	while(o.offsetParent!=null) {		// Parse the parent hierarchy up to the document element
		oParent = o.offsetParent;		// Get parent object reference
		oTop += oParent.offsetTop;		// Add parent top position
		o = oParent;
	}
	return oTop;
}
function validateData (obj,showAlert) {
	$.post($('#domainname').text()+'ajax/'+obj['pagename']+'/', obj, function(data) {
		var response = handleData(data,showAlert);
		if($("#process-spin").length > 0) {
			$("#process-spin").hide();
		}
		if(response != false) {
			window.location.href = response;
		} 
	});
}
function doRemoteAction (obj) {
	var data = null;
	$.post($('#domainname').text()+'ajax/'+obj['pagename']+'/', obj, function(data) {
		//alert('[1]'+data);
		});
}
function confirmAction (data) {
	var modalCloseLink = '<div class="errorboxclose" style="width:80px;position:relative;top;40px;cursor:pointer;"><a title="close"><img src="'+$('#imagesaddress').text()+'icondelete.png" height="16px" width="16px" alt="close" /></a></div>';

	if(data && data.length > 0) {
		var sections = data.split('|');
		$.modal(
			'<div style="background:white;border:1px solid black;padding:20px;"><a href="'+sections[0]+'">Are you sure you want to delete this job?</a></div>',
			{
				close:true,
				closeHTML: modalCloseLink
			}
			);
	} else {
		alert('nope');
	}
}
function confirmRedirect (data) {
	// msg|href
	if(data && data.length > 0) {
		var sections = data.split('|');
		// show the message
		var success = confirm(sections[0]);
		if(success) {
			// redirect
			window.location.replace(sections[1]);
		}
	}
}
function confirmAlertRedirect (data) {
	// msg|msg|href
	if(data && data.length > 0) {
		var sections = data.split('|');
		// show first message
		var success = confirm(sections[0]);
		if(success) {
			// show second message
			alert(sections[1]);
			// redirect
			window.location.replace(sections[2]);
		}
	}
}
function handleData (data,showAlert) {
	var modalCloseLink	= '<div class="errorboxclose" style="width:80px;position:relative;top:40px;cursor:pointer;"><a title="close"><img src="'+$('#imagesaddress').text()+'icondelete.png" height="16px" width="16px" alt="close" /></a></div>';

	if(data && data.length > 3) {
		var valData			= data.substr(1,data.length-2);
		var valSection		= valData.split('|');

		if(valSection.length > 1) {
			if (valSection[0] == "success") {
				if(showAlert) {
					if(valSection[4]) {
						alert(valSection[4]);
					}
				}
				return valSection[3];
			} else {
				var valFailedIDs	= '#form-' + valSection[1].split(',').join(', #form-');
				$.modal(
					valSection[2],
					{
						close:		true,
						closeHTML:	modalCloseLink
					}
					);
				$(valFailedIDs).each(function () {
					if ($(this).attr('type')=='checkbox') {
						$(this).parent().addClass("validation-fail");
					} else if ($(this).attr('type')=='radio') {
						if (($(this).parent('.radios'))||($(this).parent('.radios-down'))) {
							$(this).parent().addClass("validation-fail");
						} else if (($(this).parent().parent('.radios'))||($(this).parent().parent('.radios-down'))) {
							$(this).parent().parent().addClass("validation-fail");
						} else {
					//do nothing
					}
					} else {
						$(this).addClass("validation-fail");
						if($(this).attr("name") == "job_quote_type_uid") {
							if($("#form-job_quote_type_uid_1").length > 0) {
								$("#form-job_quote_type_uid_1").addClass("validation-fail");
							}
							if($("#form-job_quote_type_uid_2").length > 0) {
								$("#form-job_quote_type_uid_2").addClass("validation-fail");
							}
						}
					}
				});
				return false;
			}
		}
	}
	return false;
}
function selval(id) {
	return $('#'+id+' option:selected').val();
}
function getval(id) {
	if($('#'+id).length > 0) {
		return ($('#'+id).attr('value') == $('#'+id).attr('title')) ? '' : $('#'+id).attr('value');
	} else {
		return '';
	}
}
function clear_val(el) {
	if($('#'+el).attr('title')=='') {
	// do nothing
	} else {
		$('#'+el).attr('value', ($('#'+el).attr('value') == $('#'+el).attr('title')) ? '' : $('#'+el).attr('value'));
		if($('#'+el).attr('value') != $('#'+el).attr('title')) {
			$('#'+el).removeClass('pending');
		}
	}
}
function set_val(el) {
	if($('#'+el).attr('title')=='') {
	// do nothing
	} else {
		$('#'+el).attr('value', ($('#'+el).attr('value').length < 1) ? $('#'+el).attr('title') : ($('#'+el).attr('value')));
		if($('#'+el).attr('value') == $('#'+el).attr('title')) {
			$('#'+el).addClass('pending');
		}
	}
}
function getTranslation () {
	return $(".please_select").attr('title');
}

/**
 * Plugins
 */
function plugin_lea () {
	if($('.plugin-lea').length > 0 && !($.browser.msie && $.browser.version=='6.0')) {
		var base = 'http://sandbox.lea-financial-services.co.uk/scripts/';
		$.getScript(base+'jquery-1.4.min.js',function(){
			$.getScript(base+'jquery-mousewheel-3.0.2.pack.js',function(){
				$.getScript(base+'jquery-fancybox-1.3.0.pack.js',function(){
					$('head').append('<link rel="stylesheet" type="text/css" href="http://sandbox.lea-financial-services.co.uk/styles/jquery.fancybox-1.3.0.css" />');
					if($.browser.msie && $.browser.version=="6.0") {
						$('head').append('<link rel="stylesheet" type="text/css" href="http://sandbox.lea-financial-services.co.uk/styles/callback-ie6.css" />');
					}
					var referrer = escape($('#domainname').text());
					$('.plugin-lea').html('<a href="http://sandbox.lea-financial-services.co.uk/api/callback-mini/'+referrer+'" target="_new" class="iframe">Get a Quote</a>');
					$('.plugin-lea a').fancybox({
						'titleShow':			false,
						'width':				540,
						'height':				185,
						'autoScale':			false,
						'hideOnContentClick':	false,
						'onStart':				function(){},
						'onCancel':				function(){},
						'onComplete':			function(){},
						'onCleanup':			function(){},
						'onClosed':				function(){}
					});
				});
			});
		});
	}
}
$(document).ready(function() {
	/**
	* Capture the data for the paths we'll need
	*/
	var domain_name		= $("#domainname").text();
	var images			= $("#imagesaddress").text();

	/**
	* Hide any text that is not needed if JS is enabled
	*/
	$(".help-text").hide();
	$(".jshide").hide();
	$(".help img").each(function(){
		$(this).attr('alt','');
	});
	$(".subnav").hide();
	
	if(window.location.toString().indexOf("#show_hide_click",0) !== false) {
		$("#advert_plus_description_hidden").show();	
	} else {
		$("#advert_plus_description_hidden").hide();	
	}
	
	$("#show_hide_click").click(function(){
		$("#advert_plus_description_hidden").toggle();
	});
	
	var tabframelink = 'closed';
	$("#site_post_a_job_tabframe").hide();
	$("#post_job_tabframe_link").click(function(){
		if(tabframelink=='closed') {
			$("#site_post_a_job_tabframe").slideDown(800);
			tabframelink = 'open';
		} else {
			$("#site_post_a_job_tabframe").slideUp(800);
			tabframelink = 'closed';
		}
	});
	
	if($("#upgrade_successful_js").length > 0){
		alert($("#upgrade_successful_js").text());
	}

	$(".deletejob").click(function(e){
		var span_id	= $(this).parent().attr('id');
		var c_one	= $('#'+span_id+' .single-confirm').attr('title');
		var href	= $(this).attr('href');
		var data	= c_one+'|'+href;

		singleConfirm(data);
		return false;
	});

	$("#account_gallery_button").click(function(){
		var obj = {
			"pagename": "trades_advert_plus"
		};
		var data = null;
		$.post($('#domainname').text()+'ajax/'+obj['pagename']+'/', obj, function(data) {
			var valData			= data.substr(1,data.length-2);
			var valSection		= valData.split('|');
			if(valSection.length > 1){
				if(valSection[1] == 0 && valSection[0] == 'success'){

					var c_one	= $('#gallery_link_account .confirm-once').attr('title');	
					var href	= $('#gallery_link_account .link').attr('title');	
					linkdata = c_one+'|'+href;
					confirmRedirect(linkdata);
					return false;
				} else {
					window.location.replace($("#account_gallery_button").attr('href'));
				}
			}
		});
		return false;
	});



	$(".confirmonce-link").click(function(e){
		var parent_id=$(this).parent().attr('id');
		var c_one	= $('#'+parent_id+' .confirm-once').attr('title');
		var href	= $(this).attr('href');

		var data	= c_one+'|'+href;

		confirmRedirect(data);
		return false;
	});

	$(".confirmonce-link-new").click(function(e){
		
		var parent_id=$(this).attr('id');
		var c_one	= $('#'+parent_id+' .confirm-once').attr('title');
		var href	= $(this).attr('href');

		var data	= c_one+'|'+href;

		confirmRedirect(data);
		return false;
	});

	$(".confirmtwice-link").click(function(e){
		var parent_id=$(this).parent().attr('id');
		var c_one	= $('#'+parent_id+' .confirm-once').attr('title');
		var c_two	= $('#'+parent_id+' .confirm-twice').attr('title');
		var href	= $(this).attr('href');

		var data	= c_one+'|'+c_two+'|'+href;

		confirmAlertRedirect(data);
		return false;
	});
	$(".confirmonce-button").click(function(e){
		var parent_id=$(this).parent().attr('id');
		var c_one	= $('#'+parent_id+' .confirm-once').attr('title');

		var success = confirm(c_one);
		if(success) {
			$(this).parent().parent().parent().submit();
		}
		return false;
	});
	$(".confirmtwice-button").click(function(e){
		var parent_id=$(this).parent().attr('id');
		var c_one	= $('#'+parent_id+' .confirm-once').attr('title');
		var c_two	= $('#'+parent_id+' .confirm-twice').attr('title');

		var success = confirm(c_one);
		if(success) {
			success = confirm(c_two);
			if(success) {
				$(this).parent().parent().parent().submit();
			}
		}
		return false;
	});
	$(".job_listing-btn").click(function(e){
		if($(this).parent().attr('id') && $(this).parent().attr('id').length > 0) {
			var parent_id=$(this).parent().attr('id');
			var c_one	= $('#'+parent_id+' .confirm-once').attr('title');
			var c_two	= $('#'+parent_id+' .confirm-twice').attr('title');

			confirmAlertRedirect(c_one+'|'+c_two+'|'+$(this).attr('href'));
			return false;
		}
	});

	$(".job_expired-btn").click(function(e){
		var parent_id=$(this).parent().attr('id');
		var c_one	= $('#'+parent_id+' .confirm-once').attr('title');
		var c_two	= $('#'+parent_id+' .confirm-twice').attr('title');

		confirmAlertRedirect(c_one+'|'+c_two+'|'+$(this).attr('href'));

		return false;
	});

	$(".request-button").click(function(e){
		var parent_id=$(this).parent().attr('id');
		var c_one	= $('#'+parent_id+' .confirm-once').attr('title');
		var c_two	= $('#'+parent_id+' .confirm-twice').attr('title');

		var success = confirm(c_one);

		if(success) { // clicked on OK
			alert(c_two);
			return true;
		} else { // clicked on Cancel
			return false;
		}
	});

	$(".rate_trade-button").click(function(e){
		var parent_id=$(this).parent().parent().attr('id');
		var c_one	= $('#'+parent_id+' .confirm-once').attr('title');

		var success = confirm(c_one);

		if(success) { // clicked on OK
			return true;
		} else { // clicked on Cancel
			return false;
		}
	});

	$(".job-image-delete a").click(function(e){
		var span_id	= $(this).parent().attr('id');
		var c_one	= $('#'+span_id+' .confirm-once').attr('title');
		var href	= $(this).attr('href');

		var data	= c_one+'|'+href;

		confirmRedirect(data);
		return false;
	});
	
	$(".job-remove-btn a").click(function(e){
		var span_id	= $(this).parent().attr('id');
		var c_one	= $('#'+span_id+' .confirm-once').attr('title');
		var c_two	= $('#'+span_id+' .confirm-twice').attr('title');
		var href	= $(this).attr('href');

		var data	= c_one+'|'+c_two+'|'+href;

		confirmAlertRedirect(data);
		return false;
	});
	

	$('.removemyjobbutton').each(function() {
		$(this).click(function() {
			var id = $(this).attr('id').split('_');
			var res = confirm($('#removewarning_'+id[4]).attr('title'));
			if(res) {
				jQuery.data($("#form_post_a_job").get(0), "remove", id[4]);
				$('#form_post_a_job').submit();
				return false;
			} else {
				return false;
			}
		});
	});

	$('#form-inactive').click(function(){
		var parent_id = $(this).parent().parent().parent().attr('id');
		var success = confirm($('#'+parent_id+' .alert-text').attr('title'));
		if(success) {
			$(this).attr('checked',true);
		} else {
			$('#form-active').attr('checked',true);
			$(this).attr('checked',false);
		}
	});

	/**
	 * Update the select with page numbers 
	 */
	$('select.redirectionsubmit').change(function() {
		var val=$('#'+$(this).attr('id')+' option:selected').val();
		var url = domain_name + 'trade/transactions/?page='+val;
		window.location.replace(url);
	});

	/**
	* Pagination Form doesn't appear to submit
	*/
	$('.pagination-form').submit(function(){
		alert($(this).submit());
		return true;
	});

	/**
	 * My Jobs behaviours
	 */
	$('select.myjobs').change(function(){
		$(this).parent().parent().parent().parent().submit();
	});

	/**
	 * Jobs behaviours
	 */
	$('select.myjoblist').change(function(){
		$(this).parent().parent().parent().parent().submit();
		return true;
	});

	/**
	 * Deprecated
	 *-------------------------------------------------
	 $('#login-reminder').hide();
	 $('#reminder-link').click(function() {
		$('#login-reminder-form').fadeToggle('slow');
		$('#login-reminder').slideToggle('slow');
		return false;
	 });
	 *-------------------------------------------------
	 */

	/**
	 * Menu Behaviours
	 */
	var substatus = false;
	$("#menu-toggle").click(function() {
		if(substatus==false) {
			$(".subnav").show('slow');
			substatus=true;
		} else {
			$(".subnav").hide('slow');
			substatus=false;
		}
		return false;
	});

	/**
	 * Form Behaviours
	 *
	 * <input type="text" />
	 */
	$("input[type=text]").click(function() {
		$(this).removeClass('validation-fail');
	})
	$("input[type=text]").focus(function() {
		$(this).removeClass('validation-fail');
	});

	/**
	 * <textarea></textarea>
	 */
	$("textarea").focus(function() {
		if($(this).attr('id') == 'form-job_description') {
			if($(this).attr('value').split('  ').join(' ') == $('#job-description-detail-info').attr('title')) {
				$(this).attr('value','');
				$(this).removeClass('pending');
			}
		}
		$(this).removeClass('validation-fail');
	});
	$("textarea").blur(function() {
		if($(this).attr('id') == 'form-job_description') {
			if($(this).attr('value') == '') {
				$(this).attr('value',$('#job-description-detail-info').attr('title'));
				$(this).addClass('pending');
			}
		}
		$(this).removeClass('validation-fail');
	});
	$("textarea").click(function() {
		if($(this).attr('id') == 'form-job_description') {
			if($(this).attr('value').split('  ').join(' ') == $('#job-description-detail-info').attr('title')) {
				$(this).attr('value','');
				$(this).removeClass('pending');
			}
		}
		$(this).removeClass('validation-fail');
	});
	$("textarea").keyup(function(evt) {
		var code;
		if (!evt) {
			var evt = window.event;
		}
		if (evt.keyCode) {
			code = evt.keyCode;
		} else if (evt.which) {
			code = evt.which;
		}
		var character = String.fromCharCode(code);

		var class_attribute = $(this).attr("class");
		if(class_attribute.length > 0) {
			var classes = class_attribute.split(' ');
			var content = $(this).attr('value');
			var limit = 0;
			for(var i=classes.length-1; i>=0; i--) {
				if(classes[i].substring(0,5)=='limit') {
					var limit = classes[i].substring(6);
				}
			}
			if(limit > 0) {
				/**
				* There are character codes where we can ignore them and some where we should return false to stop them being used
				*/
				switch(code) {
					case 9:		// tab
					case 16:	// shift
					case 17:	// ctrl
					case 18:	// alt
					case 19:	// pause/break
					case 20:	// caps lock
					case 27:	// escape
					case 33:	// page up
					case 34:	// page down
					case 35:	// end
					case 36:	// home
					case 37:	// left arrow
					case 38:	// up arrow
					case 39:	// right arrow
					case 40:	// down arrow
					case 45:	// insert
					case 46:	// delete
					case 91:	// left window key
					case 92:	// right window key
					case 93:	// select key
					case 112:	// f1
					case 113:	// f2
					case 114:	// f3
					case 115:	// f4
					case 116:	// f5
					case 117:	// f6
					case 118:	// f7
					case 119:	// f8
					case 120:	// f9
					case 121:	// f10
					case 122:	// f11
					case 123:	// f12
						return true;
						break;
				}

				if(content.length+1 > limit) {
					$('#'+$(this).attr('id')+'-counter').text(limit);
					$(this).attr('value',$(this).attr('value').substring(0,limit));
					return false;
				}
				$('#'+$(this).attr('id')+'-counter').text($(this).attr('value').length);
				$('#'+$(this).attr('id')+'-remaining').text(limit-$(this).attr('value').length);
			}
		}
	});

	/**
	 * <input type="checkbox" />
	 */
	$('input[type=checkbox]').add('input[type=radio]').addClass('bordernone');

	/**
	 * <a rel="popup"></a>
	 */
	$("a[rel='popup']").click(function () {
		var features = "height=700,width=800,scrollTo,resizable=1,scrollbars=1,location=0";
		newwindow=window.open(this.href, 'Popup', features);
		return false;
	});

	/**
	 * <a href="help"></a>
	 */
	$("a[rel='help']").hover(function(){
		var data = $(this).attr('id');
		data = data.split('-');
		var span = 'text-'+data[1];
		JT_show(this.href,this.id,$('#'+span).text());
	});
	$("a[rel='help']").click(function(){
		return false;
	});
	$("a[rel='help']").mouseout(function(){
		$('#JT_copy').fadeOut("fast",function() {
			$('#JT').remove();
		});
	});
	$("a[rel='help']").focus(function(){
		var data = $(this).attr('id');
		data = data.split('-');
		var span = 'text-'+data[1];
		JT_show(this.href,this.id,$('#'+span).text());
	});
	$("a[rel='help']").blur(function(){
		$('#JT_copy').fadeOut("fast",function() {
			$('#JT').remove();
		});
	});

	/**
	 * Popup Details box
	 */
	$('#JT').mouseout(function(){
		this.fadeOut("fast",function(){
			$('#JT').remove();
		});
	});

	/**
	 * Multi-select
	 */
	var translated_none_selected = $("#pleaseselect").text();
	$(".multiple").each (function() {
		if(usingie7or6) {
			$(this).attr('multiple','multiple');
			$(this).attr('size','5');
			if($(this).attr('id')=='form-job_criteria_uids') {
				$(this).css('width','280px');
			}
			var pleaseselectoption = '<option>Please Select</option>';
			$(this).find("option:first").before(pleaseselectoption);
			$(this).find("option").each(function(){
				if(!$(this).is('selected')) {
					$(this).attr('selected','');
				}
			});
			document.title = $(this).attr('name');
		} else {
			var selectWidth	= $(this).width()-25;
			var parent		= $(this).parent();
			var selectID	= $(this).attr('id');
			var selectName	= $(this).attr('name');

			$(this).multiSelect({
				selectAll:			false,
				noneSelected:		translated_none_selected,
				oneOrMoreSelected:	'*'
			});

			$(parent).find(".multiSelect").attr({
				'id':		selectID,
				'name':		selectName
			}).css('width', selectWidth);
		}
	});

	/**
	 * Text Inputs
	 */
	$(".jsinnerlabel").addClass('pending').addClass('jsinnerlabel-down');

	/**
	 * All fields without labels
	 */
	$(".unlabelled").each(function(){
		if($(this).attr('value') == $(this).attr('title')) {
			$(this).addClass('pending');
		}
	});
	$(".unlabelled").click(function(){
		clear_val($(this).attr("id"));
	});
	$(".unlabelled").focus(function(){
		clear_val($(this).attr("id"));
	});
	$(".unlabelled").blur(function(){
		set_val($(this).attr("id"));
	});

	/**
	 * Unlabelled Password
	 */
	$(".unlabelled-pass").click(function(){
		$(this).parent('.password-unlabelled').find('.jsinnerlabel-down').hide();
	});
	$(".unlabelled-pass").focus(function(){
		$(this).parent('.password-unlabelled').find('.jsinnerlabel-down').hide();
	});
	$(".unlabelled-pass").blur(function(){
		if($(this).attr('value')) {
		/*do nothing*/
		} else {
			$(this).parent('.password-unlabelled').find('.jsinnerlabel-down').show();
		}
	});

	/**
	 * tabs
	 */
	$('#tabs .tab-submenubar').css({
		'border-top':'solid 1px white'
	});
	$('#tabs .tab-items .tab-item').hide();
	$('#tabs .tab-items div.tab-content').hide();
	$('#tabs .tab-items .tab-item:first').show();
	$('#tabs .tab-items div.tab-content:first').show();
	$('#tabs .tab-menubar ul li:first').addClass('current');
	$('#tabs .tab-submenubar ul li:first').addClass('current');
	$('#tabs .tab-menubar ul li a').click(function(){
		$('#tabs .tab-menubar ul li').removeClass('current');
		$(this).parent().addClass('current');
		var currentTab = $(this).attr('href');
		$('#tabs .tab-items .tab-item').hide();
		$(currentTab).show();
		$(currentTab+' .tab-menu').show();
		$(currentTab+' .tab-content-box').show();
		$(currentTab+' div.tab-content').hide();
		$(currentTab+' div.tab-content:first').show();
		$(currentTab+' .tab-submenubar ul li').removeClass('current');
		$(currentTab+' .tab-submenubar ul li:first').addClass('current');
		return false;
	});
	$('#tabs .tab-submenubar ul li a').click(function(){
		$('#tabs .tab-submenubar ul li').removeClass('current');
		var currentTab = $(this).attr('href');
		var currentSection = $(this).parent().parent().parent().parent().attr('id');
		$('#'+currentSection+' .tab-content').hide();
		$(currentTab).show();
		$(this).parent().addClass('current');
		$("a[href='"+currentTab+"']").parent().addClass('current');
		return false;
	});
	$(".tab-content a.local").click(function(){
		var href=(this.href).split('#');
		if(href.length > 1) {
			var newtab = '#'+href[1];
			$('.tab-content').hide();
			$(newtab).show();
			$(newtab).parent().addClass('current');
			$('#tabs .tab-submenubar ul li').removeClass('current');
			$("a[href='"+newtab+"']").parent().addClass('current');
		}
		return false;
	});
	
	$(".tab-content .next a,.tab-content .prev a").click(function(){
		var href=(this.href).split('#');
		if(href.length > 1) {
			var newtab = '#'+href[1];
			$('.tab-item').hide();
			$(newtab).show();
			$(newtab).find(".tab-content").show();
			$(newtab).parent().addClass('current');			
			$('#tabs ul li').removeClass('current');
			$("#tabs ul li[id='"+href[1]+"-tab']").addClass('current');
		}
		return false;
	});

	/**
	 * Enable Tabbed Navigation on Any Pages with ".tabs"
	 */
	if(typeof enable_tabs == 'function') {
		enable_tabs();
	}

	/**
	 * Homeowner/Trade Home Page Job Cascade Component
	 */
	if(typeof enable_cascade == 'function') {
		enable_cascade();
	}

	/**
	 * Form Validations
	 */
	if(typeof attach_page_validation == 'function') {
		attach_page_validation();
	}


	/**
	 * Join as a trade
	 */
	/*
	$('#container_trade_signup_form form').submit(function(e) {
		if(jQuery.browser.msie) {
			e.cancelBubble = true;
		} else {
			e.stopPropagation();
		}
		$('.validation-fail').removeClass('validation-fail');
		var firstname		= getval('form-firstname');
		var lastname		= getval('form-lastname');
		var company_name	= getval('form-company_name');
		var address_1		= getval('form-address_1');
		var address_2		= getval('form-address_2');
		var towncity		= getval('form-town_city');
		var postcode		= getval('form-postcode');
		var email			= getval('form-email');
		var email_repeat	= getval('form-email_repeat');
		var telephone_1		= getval('form-telephone_1');
		var telephone_2		= getval('form-telephone_2');
		var fax				= getval('form-fax');
		var dont_fill_in	= getval('form-dont_fill_in');
		var website			= getval('form-website');
		var trade_uids			= new Array();
		$('#trade_uids_container input[type="checkbox"]').each(function() {
			if($(this).is(':checked')) {
				trade_uids[trade_uids.length] = $(this).attr('value');
			}
		});
		trade_uids = trade_uids.join(',');
		var distance_uid	= getval('form-distance_uid');
		var language_uids	=  new Array();
		$('#language_uids_container input[type="checkbox"]').each(function() {
			if($(this).is(':checked')) {
				language_uids[language_uids.length] = $(this).attr('value');
			}
		});
		language_uids = language_uids.join(',');
		var additional			= getval('form-additional');
		var username			= getval('form-username');
		var password			= getval('form-password');
		var password_repeat		= getval('form-password_repeat');
		var referral_type_uid	= selval('form-referral_type_uid');
		var referral_type_other	= getval('form-referral_type_other');
		var terms_and_conditions= $('#form-terms_and_conditions').is(':checked') ? 1 : 0;

		// Optional
		var sticker_surface		= ($('#form-sticker-surface').length > 0) ? ($('#form-sticker-surface').is(':checked') ? 1 : 0) : 0;
		var sticker_window		= ($('#form-sticker-window').length > 0) ? ($('#form-sticker-window').is(':checked') ? 1 : 0) : 0;
		var sticker_no			= ($('#form-sticker-no').length > 0) ? ($('#form-sticker-no').is(':checked') ? 1 : 0) : 0;
		var sticker				= ((sticker_surface==1) ? 'surface' : ((sticker_window==1) ? 'window' : 'no'))
		var obj = {
			"additional":			additional,
			"address_1":			address_1,
			"address_2":			address_2,
			"company_name":			company_name,
			"distance_uid":			distance_uid,
			"dont_fill_in":			dont_fill_in,
			"email":				email,
			"email_repeat":			email_repeat,
			"fax":					fax,
			"firstname":			firstname,
			"language_uids":		language_uids,
			"lastname":				lastname,
			"pagename":				(($('#back-to-home').length > 0) ? "launch_join" : "trades_join"),
			"password":				password,
			"password_repeat":		password_repeat,
			"postcode":				postcode,
			"referral_type_other":	referral_type_other,
			"referral_type_uid":	referral_type_uid,
			"sticker":				sticker,
			"telephone_1":			telephone_1,
			"telephone_2":			telephone_2,
			"terms_and_conditions":	terms_and_conditions,
			"town_city":			towncity,
			"website":				website,
			"trade_uids":			trade_uids,
			"username":				username
		};
		validateData(obj);
		return false;
	});
	*/
	$('#form_homeowner_job_extend').submit(function() {
		$('.validation-fail').removeClass('validation-fail');
		var job_distance_uid			= selval('form-job_distance_uid');
		var job_contact_urgency_uid		= selval('form-job_contact_urgency_uid');

		var obj = {
			"job_distance_uid":			job_distance_uid,
			"job_contact_urgency_uid":	job_contact_urgency_uid,
			"pagename":					"homeowner_extend"
		};
		validateData(obj,true);
		return false;
	});
	$('#homeowner_add_photos').submit(function() {
		$('.validation-fail').removeClass('validation-fail');
		var file_uploaded				= getval('form-photo').length > 0 ? 'yes' : 'no';

		var obj = {
			"file_uploaded":			file_uploaded,
			"pagename":					"homeowner_add_photo"
		};
		if(file_uploaded=='yes') {
			return true;
		} else {
			validateData(obj);
			return false;
		}
	});

	/**
	* Google Maps
	*/
	if(typeof google_maps_plotter == 'function') {
		google_maps_plotter();
	}

	if(typeof google_plotter_three == 'function') {
		google_plotter_three();
	}
	
	if(typeof google_plotter_four == 'function') {
		google_plotter_four();
	}
	
	$("a.fancy").fancybox({
		'zoomSpeedIn':		300,
		'zoomSpeedOut':		300,
		'overlayShow':		false,
		'frameWidth':		400,
		'frameHeight':		200
	});

	$(".job_listing-job-info-col-2 .launchmap").fancybox({
		'zoomSpeedIn':		300,
		'zoomSpeedOut':		300,
		'overlayShow':		false,
		'frameWidth':		300,
		'frameHeight':		200,
		'callbackOnShow':	domap
	});

	$(".job_listing-job-info-col-2 .launchmap").click(function(){
		var usemapdiv = $(this).parent().find('div:first');
		var el2 = $(usemapdiv).attr('id');
		var el = 'fancy_div';
		var title = $('#'+el2).attr('title');
		var geocoder = new google.maps.Geocoder();
		var position;
		var myOptions = {
			zoom:						9,
			mapTypeId:					google.maps.MapTypeId.ROADMAP,
			scrollwheel:				false,
			keyboardShortcuts:			false,
			mapTypeControl:				false,
			scaleControl:				false,
			navigationControl:			true,
			navigationControlOptions:	{
				style:	google.maps.NavigationControlStyle.SMALL
			}
		};
		var mymap = new google.maps.Map(document.getElementById(el), myOptions);
		if (geocoder) {
			geocoder.geocode( {
				'address': title
			}, function(results, status) {
				if (status == google.maps.GeocoderStatus.OK) {
					var marker = new google.maps.Marker({
						map: mymap, 
						position: results[0].geometry.location,
						title: title
					});
					mymap.setCenter(results[0].geometry.location);
					mymap.panTo(results[0].geometry.location)
				} else {
					alert("Geocode was not successful for the following reason: " + status);
				}
			});
		} else {
			alert('no geocoder');
		}
		$('#fancy_div').click(function(){
			return false;
		});
	});

	function domap (overide) {
	}

	if('function' == typeof(plugin_lea)) {
		plugin_lea();
	}
	
	$(".sub_category").hide();
	$(".click_to_open").click(function(){
		$(this).parent().find("ul").toggle(400);
	});
	
	$("#click-here").fancybox({
		'zoomSpeedIn':  300,
		'zoomSpeedOut':  300,
		'overlayShow':  false,
		'frameWidth':  400,
		'frameHeight':  200
	});
	
	/* script for the show hide link */
	$("#show_hide_link").click(function(){
		
		$.post($('#domainname').text()+'ajax/jobs/', "pagename=jobs", function(data) {
			var response = handleData(data,false);
			if(response != false) {
				if($("#show_hide_link").html() == "hide details") {
					$("#show_hide_link").html("show details");
					$("#show_hide_link").parent().parent().find("div[class=clearfix]").find("div").hide();
					$("#show_hide_link").parent().parent().find("div[class=clearfix]").find("div[class=more_container]").show();
				} else {
					window.location.reload();
				}
			}
		});
		return false;
	});
	
	/*if($(".tab-content .prev a").length > 0) {
		$a = $(".tab-content .prev a");
		$a.click(function(){
			$selcted = $( "#tabs" ).tabs().( "option", "selected");
			$( "#tabs" ).tabs( "option", "selected", --$selcted );
		});
	}*/
	
	if(jQuery('#homepage-tabs').length > 0) {
		$("#homepage-tabs").tabs();
	}

	if(jQuery('#top_trades_carousel').length > 0) {
	
		jQuery('#top_trades_carousel').jcarousel({
			// Configuration goes here
			scroll: 1
		});
				 
	}
	
	if(jQuery('#recent_jobs_carousel').length > 0) {
		$('#recent_jobs_carousel').jcarousel({
			// Configuration goes here
			scroll: 1
		});		 
	}
	
	if($(".join_widget").length > 0) {
		$(".join_widget").bind("click",function() {
			//			var url = $('#domainname').text()+'trades/callback/';
			//			if($(this).hasClass("trade_join")) {
			//				url = $('#domainname').text()+'trades/callback/?q=trade_join';
			//			} else if($(this).hasClass("trade_conversion")) {
			//				url = $('#domainname').text()+'trades/callback/?q=trade_conversion';
			//			}
			//			$('.join_widget_div').html('<a href="' + url +'" target="_new" class="iframe">Need help? - request a callback?</a>');
			//			$('.join_widget_div a').fancybox({
			//				'titleShow':			false,
			//				'frameWidth':			420,
			//				'frameHeight':			330,
			//				'autoScale':			false,
			//				'hideOnContentClick':	false,
			//				'onStart':				function(){},
			//				'onCancel':				function(){},
			//				'onComplete':			function(){},
			//				'onCleanup':			function(){},
			//				'onClosed':				function(){}
			//			});
			//			$('.join_widget_div a').trigger("click");
			pshLDkow();
			return false;
		});
	}
});
