/* ==========================

THE RECEIVABLES EXCHANGE

DOCUMENT: script.js
AUTHOR: VDT
DATE: 2011.08.17

========================== */

/* Declare a namespace for the site */
var Site = window.TRE || {};

/* Create a closure to maintain scope of the '$'
   and remain compatible with other frameworks.  */
(function($) {
	
	//same as $(document).ready();
	$(function() {
				
		/* MODAL WINDOWS
		http://colorpowered.com/colorbox/
		------------------------------ */
		
		$("a#live-chat").colorbox({width:"50%", height:"70%", iframe:true, opacity:0.8});
		$("a.external-links").colorbox({width:"80%", height:"70%", iframe:true, opacity:0.8});
		$("a.external-video").colorbox({width:"50%", height:"70%", iframe:true, opacity:0.8});
		
		/* DISABLE SUBMIT
		------------------------------ */
		
		if ($("#contact-form").length) {
			$("#contact-form").submit(function(){
				$("input[type=submit]", this).attr("disabled", "disabled");
				$("input[type=submit]", this).prop("value", "Please Wait");
			});
		}
		
		
		/* JQUERY UI TABS
		------------------------------ */
		
		if ($("#tabs").length) { // Test to see if its in the page
    		$("#tabs").tabs();
			$("#tabs").css('height', $("#tabs").height());
		}
				
		/* EQUALIZE COLUMNS
		------------------------------ */
		
		if($(".equalize").length || $(".equalize-2").length || $(".equalize-3").length) { // Test to see if its in the page
			$(".equalize").equalHeights();
			$(".equalize-2").equalHeights();
			$(".equalize-3").equalHeights();
		}
				
		/* PAGE SCROLLING
		------------------------------ */
		
		$("#nav-inpage").localScroll({
		   target:'body',
		   offset: -45, // compensate for static super-nav
		   hash: true,
		   onAfter:function(){
				$(window.location.hash).animate({ backgroundColor: "#c1e0ff" }, 500);
				$(window.location.hash).delay(300).animate({ backgroundColor: "#fff" }, 1000);
			}
		});
		
		$.localScroll.hash({
			target: 'body',
			offset: -45, // compensate for static super-nav
			onAfter:function(){
				$(window.location.hash).animate({ backgroundColor: "#c1e0ff" }, 500);
				$(window.location.hash).delay(300).animate({ backgroundColor: "#fff" }, 1000);
			}
		});
		
		});

		
		/* GLOSSARY TOOLTIP
		http://craigsworks.com/projects/qtip/
		------------------------------ */
		
		$('#content a[href].glossary').each(function() {
			
			$.fn.qtip.zindex = 20000;
					
			$(this).qtip({
				content: {
					text: '<img src="/images/uploads/site/ajax-loader.gif" alt="Loading..." />',
					ajax: {
						url: $(this).attr('href'),
						type: 'GET',
						loading: false 
					}
				},
				position: {
					my: 'bottom center',  // Position my top left...
					at: 'top center', // at the bottom right of...
					target: $(this) // my target
				},
				style: {
					classes: 'ui-tooltip-blue ui-tooltip-shadow', 
					width: '280px'
				},
				show: {
					effect: function(offset) {
						$(this).fadeIn(100); // "this" refers to the tooltip
					},
					solo: true
				},
				hide: {
					delay: 500
				}
			})
			.bind('click', function(event) { // Prevent link from being followed
				event.preventDefault(); 
			})
			.attr("rel","nofollow"); // Prevent this link from being followed
		});
		
		/* APPLY NOW TOOLTIP
		http://craigsworks.com/projects/qtip/
		------------------------------ */
		
		$('.apply-now').qtip({
			content: {
				text: 'Loading...',
				ajax: {
					url: '/index.php?/widgets/tip/825', // Force the messy URL in case we lose the url title
					type: 'GET', // POST or GET
					loading: false
				}
			},
			position: {
				my: 'top right',  // Position my top left...
				at: 'bottom right' // at the bottom right of...
			},
			style: {
				classes: 'ui-tooltip-blue ui-tooltip-shadow ui-tooltip-rounded', 
				width: '320px'
			},
			show: {
				effect: function(offset) {
					$(this).slideDown(100); // "this" refers to the tooltip
				},
				solo: true, 
			},
			hide: {
				event: 'mouseleave',
				delay: 1000,
				inactive: 500000,
				fixed: true,
				effect: function(offset) {
					$(this).slideUp(200); // "this" refers to the tooltip
				}
			}
			
		})
		.bind('click', function(event) { // Prevent link from being followed
			event.preventDefault(); 
		})
		.attr("rel","nofollow"); // Prevent this link from being followed	
		
			
})(jQuery);

function getUrlVars() {
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++) {
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
return vars;
}
