google.load("swfobject", "2.1");

$(document).ready(function(){
	$('#traveler_hl_fade').delay(1500).fadeIn('slow');
	
	function hideContent() {
		$('.content_show').hide();
		$('.main_headline').hide();
		$('.hl_fade').hide();
	}
	
	function showTravelers() {
		$('#content01').show().removeClass('content_hide').addClass('content_show');
		$('#main_image_home').css('background-image','url(/Portals/_default/Skins/DFT_2011_3Q/images/main_image_travelers.jpg)');
		$('#search_trans_container').hide();
		$('#content_request').hide();
		$('#content_search').show();
		$('#search_trans_container').fadeIn('slow');
		$('#traveler_headline').fadeIn('slow');
		$('#traveler_hl_fade').delay(1500).fadeIn('slow');
	};
	
	function showEmployers() {
		$('#content02').show().removeClass('content_hide').addClass('content_show');
		$('#main_image_home').css('background-image','url(/Portals/_default/Skins/DFT_2011_3Q/images/main_image_facilities.jpg)');
		$('#search_trans_container').hide();
		$('#content_search').hide();
		$('#content_request').show();
		$('#search_trans_container').fadeIn('slow');
		$('#employer_headline').fadeIn('slow');
		$('#employer_hl_fade').delay(1500).fadeIn('slow');
	};
	
	function showCustomerExp() {
		$('#content03').show().removeClass('content_hide').addClass('content_show');
		$('#main_image_home').css('background-image','url(/Portals/_default/Skins/DFT_2011_3Q/images/main_image_cxp.jpg)');
		$('#search_trans_container').hide();
		$('#cxp_headline').fadeIn('slow');
		$('#cxp_hl_fade').delay(1500).fadeIn('slow');
	}
	
	
	//content change function
	function change_content(tab){
		hideContent();
		
		if(tab == 'tab01'){
			showTravelers();
		} else if (tab =='tab02'){
			showEmployers();
		} else {
			showCustomerExp();
		};
	};
	
	//tab functions
	$('.tab_back').live({
		click: function() {
			$('.tab').removeClass('tab_front tab_hover').addClass('tab_back').css('height','14px');
			$(this).removeClass('tab_back').addClass('tab_front');
			$('.tab_back').css('height','14px');
			$('.tab_front').css('height','19px');
			change_content(this.id);
		},
		mouseover: function() {
			$(this).animate({height:'19px'},75,function() {
			// Animation complete.
			});
			$(this).addClass('tab_hover');
		},
		mouseout: function() {
			$(this).animate({height:'14px'},100,function() {
		  		$(this).clearQueue();
			});
			$(this).removeClass('tab_hover');
		}
	});
	
	
	//social icon functions
	$('#social_icons div').live({
		click: function() {
			if(this.id == 'twitter') {
				window.open("http://www.twitter.com/tdcpeople");
			}
			if(this.id == 'facebook') {
				window.open("http://www.facebook.com/deltaflextravelers");
			}
			if(this.id == 'youtube') {
				window.open("http://www.youtube.com/tdcpeople");
			}
		},
		mouseover: function() {
			$(this).css({'background-image':'url(/Portals/_default/Skins/DFT_2011_3Q/images/social/'+this.id+'_over.png)'});			
		},
		mouseout: function() {
			$(this).css({'background-image':'url(/Portals/_default/Skins/DFT_2011_3Q/images/social/'+this.id+'_up.png)'});
		}
	});

	//traveler resources functions
	$('.tr_tab_back').live({
		click: function() {
			$('.tr_container').hide();
			$('#'+this.id+'_container').show();
			$('.tr_tab').removeClass('tr_tab_front').addClass('tr_tab_back');
			$(this).removeClass('tr_tab_back tr_tab_hover').addClass('tr_tab_front');
		},
		mouseover: function() {
			$(this).addClass('tr_tab_hover');
		},
		mouseout: function() {
			$(this).removeClass('tr_tab_hover');
		}
	});
	
	// video feature functions
	$('.video_thumb').live({
		click: function() {
			var video_id = this.id;
			var params = { allowScriptAccess: "always" };
  			var atts = { id: "ytPlayer" };
			var url = "http://www.youtube.com/v/" + video_id + "?version=3&enablejsapi=1&playerapiid=player1&showinfo=0&rel=0&autoplay=1&modestbranding=1";
  			swfobject.embedSWF(url, "videoDiv", "488", "293", "9", null, null, params, atts);
			$('#pop_up_cover').show();
		},
		mouseover: function() {
			$(this).addClass('vid_thumb_hover');
		},
		mouseout: function() {
			$(this).removeClass('vid_thumb_hover');
		}
	});
	$('#close_button').click(function() {
		$('#pop_up_cover').hide();
		swfobject.removeSWF("ytPlayer");
		$('#video_container').append("<div id='videoDiv'></div>");
	});
	
	// search jobs functions
	$('.sj_job_title').live({
		click: function() {
			var expand = 'detail_' + this.id;
			$('#' + expand).toggle('fast');
		}
	});
	
	
	function gup(name){
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec( window.location.href );
		if( results == null ){
			return "";
		} else {
			return results[1];
		}
	}
	
	var tab = gup('tab');
	
	if(tab == 'employers'){
		$('.tab').removeClass('tab_front tab_hover').addClass('tab_back').css('height','14px');
		$('#tab02').removeClass('tab_back').addClass('tab_front');
		$('.tab_back').css('height','14px');
		$('.tab_front').css('height','19px');
		hideContent();
		showEmployers();
	}
	if(tab == 'customer_experience'){
		$('.tab').removeClass('tab_front tab_hover').addClass('tab_back').css('height','14px');
		$('#tab03').removeClass('tab_back').addClass('tab_front');
		$('.tab_back').css('height','14px');
		$('.tab_front').css('height','19px');
		hideContent();
		showCustomerExp();
	}
});
