﻿var $j = jQuery.noConflict();


/**
	Variable global namespace container
	@namespace
	@requires jQuery.js
*/
var TA = {};

/**
	@class
	@description General page initialization
*/
TA.general = {

	/**
		inicicalizamos los app functions
	*/
	init: function() {
		TA.general.setGlobals();
		TA.general.matchHeights();
		
	},
	
	/**
		Set global functions
	*/
	setGlobals: function() {
		$j('body').addClass('has-js');
		$j('a[rel=external]').attr('target','_blank');
		$j('a[href=#]').click( function(e) {
			e.preventDefault();
		});		
	},
	
	/**
		Height matcher 
	*/
	matchHeights: function(set) {
		$j('#layer-base, #layer-top, .exposed, ').matchColumns();
		$j('.col-content').each( function() {
			//$j(this).find('li').matchColumns();
		});

	}

};

/**
	@class
	@description Home slider
*/
TA.homeSlider = {

	processing: false,
	slideAll: false,
	offsetWrapper: 0,
	offsetContent: 0,
	offsetLogo: 0,
	targetLogo: '0px',
	speed: 800,

	init: function() {
		// set defaults
		TA.homeSlider.slideAll = $j('body').hasClass('v2');
		TA.homeSlider.offsetMargin = $j('#layer-top .container').css('marginRight');
		TA.homeSlider.offsetWrapper = $j('#layer-top').css('width');
		TA.homeSlider.offsetWrapper 
		//TA.homeSlider.offsetLogo = $j('#logo').css('marginLeft');
		// set event handler
		$j('.btn-open-close').live('click', function(e) {
			e.preventDefault();
			if ( !TA.homeSlider.processing ){
				
				if ($j('#layer-top').hasClass('open')) {
					TA.homeSlider.close();
					
				}else{
					TA.homeSlider.open();	
					
					var t=setTimeout("TA.homeSlider.processing = false;",2000);
						
				}
				
			}
		});


	},
	
	open: function() {
		
		//createCookie("slider","open");
		
		TA.homeSlider.processing = true;
		$j('#right-content').removeClass('hide-content');
		
		$j('#right-content').addClass('reveal-content');
		
		$j('#layer-top').addClass('processing');
		
		$j('#layer-base .container, #homeHero').animate({ opacity: .4 }, 150 , 'easeInOutCubic', function() {
			
			$j('#layer-top .container').animate({ marginRight: 0	}, TA.homeSlider.speed , 'easeInOutCubic', function() {
				
				$j('#layer-top').addClass('open');
				$j('#layer-top').removeClass('processing');
				
				$j('#layer-top .logo').fadeIn();
				
			});
			
		    s.linkTrackVars='prop1';
		    s.prop1="home page slider close";
		    s.pageName = "tormo home close";
		    s.t();		
			
			
			if( TA.homeSlider.slideAll ) $j(this).animate({ marginLeft: TA.homeSlider.offsetMargin }, TA.homeSlider.speed , 'easeInOutCubic' );	
			
		});
		
		
	},

	
	close: function() {
		//eraseCookie("slider");
		TA.homeSlider.processing = true;
		$j("#layer-top").removeClass('open');
		TA.homeSlider.processing = true;
		$j('#layer-top').addClass('processing');
		$j('#layer-top .logo').fadeOut( function() {
			$j('#layer-top .container').animate({ marginRight: TA.homeSlider.offsetMargin }, TA.homeSlider.speed, 'easeInOutCubic', function() {
				$j('#layer-base .container, #homeHero').animate({ opacity: 1 }, 450 , 'easeInOutCubic', function() {
					$j('#layer-top').removeClass('processing');
					$j('#right-content').addClass('hide-content');
					$j('#right-content').removeClass('reveal-content');

					TA.homeSlider.processing = false;
					
				});
			});
		});

		if( TA.homeSlider.slideAll ) $j('#layer-base .container').animate({ marginLeft: 0 }, TA.homeSlider.speed , 'easeInOutCubic' );
		
	}
	
}



/**
	@class
	@description Home world map
*/
TA.homeMap = {

	init: function() {
		// set defaults
		$j('.finder-container').css('display','none');
		
		//on click of the button in the map
		$j("#tasoc-map li").click(function(){
			var eId = $j(this).attr('id')+'-offices'; //get the button id
			$j("#"+eId).show().children('.clearfix').show(); 
			$j("#"+eId).siblings('div').hide(); //hide all of the other flyouts with the countries
		});
		
		//on click of the blue close button on the country flyouts
		$j(".close").click(function(){
			$j(this).parent().hide();//hide the flyout
		});

		
	}
	
}




/**
	On document ready
*/
$j(document).ready(function() {
	/*TA.noConflict();*/
	TA.general.init();
	TA.homeSlider.init();
	TA.homeMap.init();
	$j(window).resize(function() {
	  $j('#layer-base, #layer-top, .exposed, ').matchColumns();
	});	
	
	
});

/*This function controlls the hover state of the global nav. It adds a slow delay ~1000 ms and sets the background color of the hovered element accordingly*/
$j(function() {
    hiConfig = {
        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
        interval: 100, // number = milliseconds for onMouseOver polling interval
        timeout: 0, // number = milliseconds delay before onMouseOut
        over: function() {
            $j(this).children('.flyout-container').show();
			//$j(this).children('.parent').css('backgroundColor','#00adef');
        }, // function = onMouseOver callback (REQUIRED)
        out: function() { 
			$j(this).children('.flyout-container').hide();
			//$j(this).children('.parent').css('backgroundColor','');
		}
    }
   $j("#nav li").hoverIntent(hiConfig)
});
/**
 	PLUGINS
*/

$j.fn.matchColumns = function(){
	

	var height_tar = $j(document).height();
	/*$j(this).each(function(){
		height_obj = $j(this).outerHeight();
		height_tar = $j(document).height();
	});*/

	/*$j(this).each(function(){
		var pad_top = parseInt($j(this).css("padding-top"));
		var pad_bot = parseInt($j(this).css("padding-bottom"));
		var bor_top = parseInt($j(this).css("border-top-width"));
		var bor_bot = parseInt($j(this).css("border-bottom-width"));
		
		var offset = pad_top + pad_bot + bor_top + bor_bot;

		// fix for ie6
		if ($j.browser.msie){
			$j(this).css({'height': (height_tar - offset + 129) + "px"});
			}
		else{
			alert("height_Tar "+height_tar+" offset "+offset);
			
			}
	});*/
	
	$j(this).css({"height": (height_tar ) + "px"});
}; // matchColumns


/*
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else {
     	var futdate = new Date()		//Get the current time and date
      	var expdate = futdate.getTime()  //Get the milliseconds since Jan 1, 1970
      	expdate += 3600*1000  //expires in 1 hour(milliseconds)
      	futdate.setTime(expdate)
      	var expires = "";
      	expires = "; expires=" + futdate.toGMTString()
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	//createCookie(name,"",-1);
}


function ResetSliderCookie() {
	//eraseCookie("slider");
}
*/
function PreloadSlider() {
	/*
	if(readCookie("slider") == "open")
	{
		
		$j('#right-content').removeClass('hide-content');
		$j('#right-content').addClass('reveal-content');
		//TA.homeSlider.processing = true;
		$j('#layer-top').addClass('processing');
		$j('#layer-base .container').animate({ opacity: .4 }, 450 , 'easeInOutCubic', function() {
			$j('#layer-top .container').css('marginRight', '0px');
			$j('#layer-top').addClass('open');
			$j('#layer-top').removeClass('processing');
			TA.homeSlider.processing = false;
			$j('#layer-top .logo').fadeIn();
			
			if( TA.homeSlider.slideAll ) $j(this).css('marginLeft', TA.homeSlider.offsetMargin);
			
		});
		*/
	
}


 var textboxvalue
 function doClear(obj) 
 {
    obj.value = "";
 }

 function ImageButton_Click() {
     if (document.getElementById("<%=TextBoxSearch.ClientID%>").value == "" || document.getElementById("<%=TextBoxSearch.ClientID%>").value == "Search") {
         alert("Please enter one or more search terms");
         document.getElementById("<%=TextBoxSearch.ClientID%>").focus();
         return false;
     }
 return true;
 }
