/**
* purpose to be use in jobs-home template
*
* @modified by Abdul Othman 201/08/18
*/

(function($) {

	$(document).ready(function(){

		$(".main_image .desc").show(); //Show Banner
		$(".main_image .block").animate({ opacity: 1 }, 1 ); //Set Opacity

		// #Main Tabs
		var tabContainers = $('div.country-tabs > div');

		$('div.country-tabs ul.country-tabnav a').click(function () {
			tabContainers.hide().filter(this.hash).show();
			$('div.country-tabs ul.country-tabnav li').removeClass('selected');
			$(this.parentNode).addClass('selected');

			// call the container
			var containerid = this.hash;
			var liactive = false;
			// check active li
			$(containerid+" .image_thumb ul li").each(function(index){
				if ($(this).hasClass("active")) {
					liactive = true;
				}
			});
			if (liactive === false) $(containerid+" .image_thumb ul li:first").addClass('active');

			// animate the container
			tabSelection(containerid);

			return false;
		}).filter(':first').click();

	});	// Close Function


	function tabSelection(containerid){

		$(containerid+" .image_thumb ul li").click(function(){

			//Set Variables
			var imgLink = $(this).find('a.btn-standard').attr("href"); //Get Alt Tag of Image
			var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
			var imgTitle = $(this).find('a.image_ref').attr("href"); //Get Main Image URL
			var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
			var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block

			if ($(this).is(".active")) {  //If it's already active, then...
			//	return false; // Don't click through
			} else {
				//Animate the Teaser
				$(containerid+" .main_image a.slide-img-link").animate({ opacity: 0}, 250 );
				$(containerid+" .main_image .block").animate({ opacity: 0, marginLeft: -imgDescHeight }, 250 , function() {
					$(containerid+" .main_image img").attr({ src: imgTitle , alt: imgAlt});
					$(containerid+" .main_image .block").html(imgDesc).animate({ opacity: 1,	marginLeft: "0" }, 250 );
					$(containerid+" .main_image a.slide-img-link").attr({ href: imgLink}).animate({ opacity: 1}, 250 );
				});
			}

			$(containerid+" .image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
			$(this).addClass('active');  //add class of 'active' on this list only
			// return false;

		}) .hover(function(){
			$(this).addClass('hover');
			}, function() {
			$(this).removeClass('hover');
		});

		//Toggle Teaser
		$("a.collapse").click(function(){
			$(".main_image .block").slideToggle();
			$("a.collapse").toggleClass("show");
		});
	}

	// continent > /tefl-jobs-abroad/destinations/ - ajax called
	$(document).ready(function(){

		/* FAQ Tabs */
		var faqTabs = $('div#faq-tabs-hook > div');
		$('div#faq-tabs ul.faq-tabnav a').click(function () {

			var sc_load_img 	= '<img alt="loading" title="loading" src="/images/common/loading.gif" />';
			var sc_load_text 	= 'loading...';
			var sc_url 				= '/ajax/teflFeeds.ajax.php';
			var cattype = "&cat_type="+$(this.hash+"-cattype").val();
			var catname = "&cat_name="+$(this.hash+"-catname").val();
			var sc_qs = "&limit="+$(this.hash+"-limit").val() + cattype + catname;

			faqTabs.hide().filter(this.hash).show();
			$('div#faq-tabs ul.faq-tabnav li').removeClass('nav-selected');
			$(this.parentNode).addClass('nav-selected');

			// reload content area
			$(this.hash+"-feed")
					.html(sc_load_img +" "+ sc_load_text)
					.load(sc_url+"?sctype=continent-faq"+sc_qs, function() {
					});

			return false;
		}).filter(':first').click();

	});

})(jQuery);
