
/* =Persisitant Header Function
================================================== */
function updatePersistantHeader() {
	
	jQuery('.floatingWidget').each(function() {
		
		var el             = jQuery('.sidebar'),
				offset         = el.offset(),
				scrollTop      = jQuery(window).scrollTop(),
				floatingWidget = jQuery(this);

			if ( scrollTop > ( el.height() - ( floatingWidget.height() - 120 ) ) ) {
					floatingWidget.css({ "display": "block" });
       	} else {
           floatingWidget.css({ "display": "none" });
       	};

	});	
}

/* trigger when page is ready */
jQuery(document).ready(function ($){

	/* =Tabs Activiation
	================================================== */
	var tabs = $('ul.tabs');
	
	tabs.each(function(i) {
		//Get all tabs
		var tab = $(this).find('> li > a');
		tab.click(function(e) {
			
			//Get Location of tab's content
			var contentLocation = $(this).attr('href') + "Tab";
			
			//Let go if not a hashed one
			if(contentLocation.charAt(0)=="#") {
			
				e.preventDefault();
			
				//Make Tab Active
				tab.removeClass('active');
				$(this).addClass('active');
				
				//Show Tab Content & add active class
				$(contentLocation).show().addClass('active').siblings().hide().removeClass('active');
				
			} 
	
		});
		
	});
	
	/* =JQuery Cycle Slideshow.
	================================================== */
	if ( $('#slideshow').length >= 1 ){
		
		$('#slideshow').cycle({
			fx: 'fade',
			speed: 'slow',
			timeout: 7000,
			pager:  '#slide-nav',
			slideExpr: 'div.slide'
		});

		$('#playpause.pause').live('click', function(){
			$(this).removeClass('pause').addClass('play');
			$('#slideshow').cycle('pause');
		});
		$('#playpause.play').live('click', function(){
			$(this).removeClass('play').addClass('pause');
			$('#slideshow').cycle('resume');
		});
	
	} 

	/* =Companies dropdown.
	================================================== */
	// $('.companies li').hover(function(){
	// 	console.log($(this).find('.hover-item'));
	// 	$(this).find('.hover-item').slideDown();

	// }, function(){

	// 	$(this).find('.hover-item').slideUp();
	
	// });


	$(".downloadform").colorbox({
		width:'600px',
		onComplete: function(){
			$("#input_3_7").val( $("#formrequested").html() );
			console.log($("#formrequested").html());
		}
	});
	// $("#input_3_7").val( $("#formrequested").html() );

	/* =Persisitant Header js
	================================================== */
	var clonedHeaderRow;
	$('#text-5, #text-7, #text-8').addClass('persistant-widget');

   $(".persistant-widget").each(function() {
			clonedHeaderRow = $(this);
			clonedHeaderRow.before(clonedHeaderRow.clone()).css("width", clonedHeaderRow.width()).addClass("floatingWidget");
			$('#main-side').append(clonedHeaderRow);
   });

   $(window)
    .scroll(updatePersistantHeader)
    .trigger("scroll");
});
