//Homepage sliding banner	
/* Carousel Pack */

/* pack : 1  http://thomlx.free.fr/js/jquery.carousel.pack.js*/
;(function($){$.fn.carousel=function(params){var params=$.extend({direction:"horizontal",loop:false,dispItems:1,pagination:false,paginationPosition:"inside",nextBtn:"<span>Next</span>",prevBtn:"<span>Previous</span>",btnsPosition:"inside",nextBtnInsert:"appendTo",prevBtnInsert:"prependTo",autoSlide:false,autoSlideInterval:3000,delayAutoSlide:3000,combinedClasses:false,effect:"slide",slideEasing:"swing",animSpeed:"normal",equalWidths:"true",callback:function(){}},params);if(params.btnsPosition=="outside"){params.prevBtnInsert="insertBefore";params.nextBtnInsert="insertAfter";}
return this.each(function(){var env={$elts:{},params:params,launchOnLoad:[]};env.$elts.carousel=$(this).addClass("js");env.$elts.content=$(this).children().css({position:"absolute","top":0});env.$elts.wrap=env.$elts.content.wrap('<div class="carousel-wrap"></div>').parent().css({overflow:"hidden",position:"relative"});env.steps={first:0,count:env.$elts.content.find(">*").length};env.steps.last=env.steps.count-1;env.$elts.prevBtn=$(params.prevBtn)[params.prevBtnInsert](env.$elts.carousel).addClass("carousel-control previous carousel-previous").data("firstStep",-(env.params.dispItems));env.$elts.nextBtn=$(params.nextBtn)[params.nextBtnInsert](env.$elts.carousel).addClass("carousel-control next carousel-next").data("firstStep",env.params.dispItems);initButtonsEvents(env,function(e){slide(e,this,env);});if(env.params.pagination)initPagination(env);$(function(){var $firstItem=env.$elts.content.find(">*:eq(0)");env.itemWidth=$firstItem.outerWidth();if(params.direction=="vertical"){env.contentWidth=env.itemWidth;}else{if(params.equalWidths){env.contentWidth=env.itemWidth*env.steps.count;}else{env.contentWidth=(function(){var totalWidth=0;env.$elts.content.find(">*").each(function(){totalWidth+=$(this).outerWidth();});return totalWidth;})();}}
env.$elts.content.width(env.contentWidth);env.itemHeight=$firstItem.outerHeight();if(params.direction=="vertical"){env.$elts.content.css({height:env.itemHeight*env.steps.count+"px"});env.$elts.content.parent().css({height:env.itemHeight*env.params.dispItems+"px"});}else{env.$elts.content.parent().css({height:env.itemHeight});}
updateButtonsState(env);$.each(env.launchOnLoad,function(i,fn){fn();});if(env.params.autoSlide){window.setTimeout(function(){env.autoSlideInterval=window.setInterval(function(){env.$elts.nextBtn.click();},env.params.autoSlideInterval);},env.params.delayAutoSlide);}});});};function slide(e,btn,env){var $btn=$(btn);var newFirstStep=$btn.data("firstStep");env.params.callback(newFirstStep);switch(env.params.effect){case"no":if(env.params.direction=="vertical"){env.$elts.content.css("top",-(env.itemHeight*newFirstStep)+"px");}else{env.$elts.content.css("left",-(env.itemWidth*newFirstStep)+"px");}
break;case"fade":if(env.params.direction=="vertical"){env.$elts.content.hide().css("top",-(env.itemHeight*newFirstStep)+"px").fadeIn(env.params.animSpeed);}else{env.$elts.content.hide().css("left",-(env.itemWidth*newFirstStep)+"px").fadeIn(env.params.animSpeed);}
break;default:if(env.params.direction=="vertical"){env.$elts.content.stop().animate({top:-(env.itemHeight*newFirstStep)+"px"},env.params.animSpeed,env.params.slideEasing);}else{env.$elts.content.stop().animate({left:-(env.itemWidth*newFirstStep)+"px"},env.params.animSpeed,env.params.slideEasing);}}
env.steps.first=newFirstStep;updateButtonsState(env);if(!!e.clientX&&env.autoSlideInterval){window.clearInterval(env.autoSlideInterval);}};function updateButtonsState(env){env.$elts.prevBtn.data("firstStep",env.steps.first-env.params.dispItems);env.$elts.nextBtn.data("firstStep",env.steps.first+env.params.dispItems);if(env.$elts.prevBtn.data("firstStep")<0){if(env.params.loop&&env.steps.count>env.params.dispItems){env.$elts.prevBtn.data("firstStep",env.steps.count-env.params.dispItems);env.$elts.prevBtn.trigger("enable");}else{env.$elts.prevBtn.trigger("disable");}}else{env.$elts.prevBtn.trigger("enable");}
if(env.$elts.nextBtn.data("firstStep")>=env.steps.count){if(env.params.loop&&env.steps.count>env.params.dispItems){env.$elts.nextBtn.data("firstStep",0);env.$elts.nextBtn.trigger("enable");}else{env.$elts.nextBtn.trigger("disable");}}else{env.$elts.nextBtn.trigger("enable");}
if(env.params.pagination){env.$elts.paginationBtns.removeClass("active").filter(function(){return($(this).data("firstStep")==env.steps.first)}).addClass("active");}};function initButtonsEvents(env,slideEvent){env.$elts.nextBtn.add(env.$elts.prevBtn).bind("enable",function(){var $this=$(this).bind("click",slideEvent).removeClass("disabled");if(env.params.combinedClasses){$this.removeClass("next-disabled previous-disabled");}}).bind("disable",function(){var $this=$(this).unbind("click").addClass("disabled");if(env.params.combinedClasses){if($this.is(".next")){$this.addClass("next-disabled");}else if($this.is(".previous")){$this.addClass("previous-disabled");}}});env.$elts.nextBtn.add(env.$elts.prevBtn).hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");});};function initPagination(env){env.$elts.pagination=$('<div class="center-wrap"><div class="carousel-pagination"><p></p></div></div>')[((env.params.paginationPosition=="outside")?"insertAfter":"appendTo")](env.$elts.carousel).find("p");env.$elts.paginationBtns=$([]);env.$elts.content.find("li").each(function(i){if(i%env.params.dispItems==0){env.$elts.paginationBtns=env.$elts.paginationBtns.add($('<a role="button"><span>'+(env.$elts.paginationBtns.length+1)+'</span></a>').data("firstStep",i));}});env.$elts.paginationBtns.appendTo(env.$elts.pagination);env.$elts.paginationBtns.slice(0,1).addClass("active");env.launchOnLoad.push(function(){env.$elts.paginationBtns.click(function(e){slide(e,this,env);});});};})(jQuery);




	
$(document).ready(function(){
        //Homepage CV window
		$("#cv_submit").click(function () {
			$("#cv_open").dialog("destroy");
			$("#cv_open").dialog({modal: true, title: 'Submit your CV', width: 618, height: 935});
		});
		/*
		//function for auto complete select dropdown for job search
			(function( $ ) {
				$.widget( "ui.combobox", {
					_create: function() {
						var self = this,
							select = this.element.hide(),
							selected = select.children( ":selected" ),
							value = selected.val() ? selected.text() : "";
						var input = this.input = $( "<input />" )
							.insertAfter( select )
							.val( value )
							.autocomplete({
								delay: 0,
								minLength: 0,
								source: function( request, response ) {
									var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
									response( select.children( "option" ).map(function() {
										var text = $( this ).text();
										var c_name = $( this ).attr("class");
										if ( this.value && ( !request.term || matcher.test(text) ) )
											return {
												label: text.replace(
													new RegExp(
														"(?![^&;]+;)(?!<[^<>]*)(" +
														$.ui.autocomplete.escapeRegex(request.term) +
														")(?![^<>]*>)(?![^&;]+;)", "gi"
													), "<strong>$1</strong>" ),
												value: text,
												class_name: c_name,
												option: this
											};
									}) );
								},
								select: function( event, ui ) {
									ui.item.option.selected = true;
									self._trigger( "selected", event, {
										item: ui.item.option
									});
								},
								change: function( event, ui ) {
									if ( !ui.item ) {
										var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
											valid = false;
										select.children( "option" ).each(function() {
											if ( $( this ).text().match( matcher ) ) {
												this.selected = valid = true;
												return false;
											}
										});
										if ( !valid ) {
											// remove invalid value, as it didn't match anything
											$( this ).val( "" );
											select.val( "" );
											input.data( "autocomplete" ).term = "";
											return false;
										}
									}
								}
							})
							.addClass( "ui-widget ui-widget-content ui-corner-left" );

						input.data( "autocomplete" )._renderItem = function( ul, item ) {
							return $( "<li></li>" )
								.data( "item.autocomplete", item )
								.append( "<a class='" + item.class_name + "'>" + item.label + "</a>" )
								.appendTo( ul );
						};

						this.button = $( "<button type='button'>&nbsp;</button>" )
							.attr( "tabIndex", -1 )
							.attr( "title", "Show All Items" )
							.insertAfter( input )
							.button({
								icons: {
									primary: "ui-icon-triangle-1-s"
								},
								text: false
							})
							.removeClass( "ui-corner-all" )
							.addClass( "ui-corner-right ui-button-icon" )
							.click(function() {
								// close if already visible
								if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
									input.autocomplete( "close" );
									return;
								}

								// work around a bug (likely same cause as #5265)
								$( this ).blur();

								// pass empty string as value to search for, displaying all results
								input.autocomplete( "search", "" );
								input.focus();
							});
					},

					destroy: function() {
						this.input.remove();
						this.button.remove();
						this.element.show();
						$.Widget.prototype.destroy.call( this );
					}
				});
			})( jQuery );		
		
		//Job Search auto complete
		$( "#srch_industry" ).combobox();
		$( "#srch_locations" ).combobox();
		$( "#srch_worktypes" ).combobox();
		
		
		$( "#toggle" ).click(function() {
			$( "#combobox" ).toggle();
		});	
		*/
		
		//---
		// Footer Slide out drawer
		$("#toggle a").click(function () {
			$("#linkPanel").slideToggle("slow");
		});	
		//---
		//Top slidedown drawer
		$(".trigger").click(function(){
		if ($("#topslide-inner").is(":hidden")){
					$("#topslide-inner").slideDown("slow");
				}
		  else{
					$("#topslide-inner").slideUp("slow");
		 }
		});
		//---
		//TABS THAT APPEAR ON EVERY PAGE
		//Default Action
		$(".tab_content").hide(); //Hide all content
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content
		
		//On Click Event
		$("ul.tabs li").click(function() { 
			$("ul.tabs li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content").hide(); //Hide all tab content
			var activeTab = $(this).find("a").attr("rel"); //Find the rel attribute value to identify the active tab + content
			$(activeTab).show(); //Fade in the active content
			return false;
		});
		//---
		
		
		
		
		//---
		//banner missing
		$('.banner img').error(function() {
			$(this).attr({
			  src: '../template_images/generic.jpg',
			  alt: 'Careers Unlimited'
			});
		  });
		
		//JOB RSS POP- UP
		$('#rssLink a').click(function(){
				$( "#jobRss" ).dialog( "destroy" );					   
				$( "#jobRss" ).dialog({
								modal: true,
								title: 'RSS Feed',
								width: 500,
								height: 300
								});
					   
		});
		//JOB SUBSCRIBE POP- UP
		$('#jobAlertLink a').click(function(){
				$( "#jobAlert" ).dialog( "destroy" );							
				$( "#jobAlert" ).dialog({
								modal: true,
								title: 'Sign up for Job alerts',
								width: 500,
								height: 300
								});
					   
		});
		
	
		//Homepage banner rotator
		$("div.carousel").carousel({
			/*direction: "verical",*/
			/*dispItems: 3,*/
			/*effect: "fade",*/
			pagination: true,
			autoSlide: true, 
        	autoSlideInterval: 3000,
			loop: true
		});
		
		
		
		
		
});

// JavaScript Document//clear text box on click
function clearText(field){

if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;

}
//---
// Hour switcher
function showhide(id){
	if (document.getElementById){
		obj = document.getElementById(id);
		if (obj.style.display == "none"){
		obj.style.display = "block";
		} else {
		obj.style.display = "none";
		}
	}
}
function show(id){
	if (document.getElementById){
		obj = document.getElementById(id);
		obj.style.display = "block";
	}
}
function hide(id){
	if (document.getElementById){
		obj = document.getElementById(id);
		obj.style.display = "none";
	}
}

function validate_ja(){		
		
	if($("input[name='ja_name']").val() == "Name")
		$("input[name='ja_name']").val("");
	if($("input[name='ja_email']").val() == "Email Address")
		$("input[name='ja_email']").val("");
	if($("input[name='ja_surname']").val() == "Surname")
		$("input[name='ja_surname']").val("");
	if($("input[name='ja_phone']").val() == "Phone")
		$("input[name='ja_phone']").val("");
	
}

