$(function() {
	// Tabsets
	$(".tabset").length ? $(".tabset").tabs() : null;
	
	// Jumpmenus
	$(".jumpmenu").change(function() {
		var val = $(this).attr("value");
		val != '' ? location.href = val : null;
	});
	
	// Modal Windows
	var $modalWindow = $('<div id="modal-window" class="jqmWindow"><button type="button" class="jqmClose">Close Window</button><iframe id="jqmContent" src="" width="100%" height="100%" frameBorder="0"></iframe></div>');
	$modalWindow.appendTo("body:not(.window)");
	
	var modal = {
		open: function(hash) {
			hash.o.hide().fadeIn('1000', function() {
				hash.w.fadeIn('1000');
				jqmWindowOffset = ($(window).height() - hash.w.outerHeight())/2;
				hash.w.css("top", jqmWindowOffset + "px");
			});
		},
		close: function(hash) {
			hash.w.fadeOut('1000', function() {
				hash.o.fadeOut('1000', function() {
					hash.o.remove();
				});
			});
		}
	};	
	
	$.jqm.params.modal = true;
	$.jqm.params.toTop = true;
	$.jqm.params.overlay = 100;
	
	$(document).keydown(function(e) {
		if(e.which == 27) {  // escape, close box
			$(".jqmWindow").jqmHide();
		}
	});
	
	var loadInIframeModal = function(hash){
		var $trigger = $(hash.t);
		var $modal = $(hash.w);
		var myUrl = $trigger.attr('href');
		var $modalContent = $("iframe", $modal);
		
		$modalContent.html('').attr('src', myUrl);
		modal.open(hash);
	}
	
	$('#modal-window').jqm({
		trigger: $(".modal"),
		target: '#jqmContent',
		onShow:  loadInIframeModal,
		onHide: modal.close
	});
    
	// Tool Tips for Features Tabset
	if ($(".tabset.icons").length != 0) {
		$.fn.qtip.styles.gw = {
			padding: 10,
			border: 0,
			width: {
				min: 0,
				max: 600
			},
			background: '#77b800',
			color: '#FFF',
			tip: {
				corner: 'bottomMiddle',
				color: '#77b800',
				size: {
					x: 14,
					y : 12
				}
			}
		}
		
		$.fn.qtip.styles.yellow = { background: '#ffcb05', tip: { color: '#ffcb05' }, name: 'gw' }
		$.fn.qtip.styles.blue = { background: '#0061af', tip: { color: '#0061af' }, name: 'gw' }
		$.fn.qtip.styles.red = { background: '#d7182a', tip: { color: '#d7182a' }, name: 'gw' }
		$.fn.qtip.styles.orange = { background: '#f99f1c', tip: { color: '#f99f1c' }, name: 'gw' }
		$.fn.qtip.styles.purple = { background: '#812990', tip: { color: '#812990' }, name: 'gw' }
		$.fn.qtip.styles.brown = { background: '#754c24', tip: { color: '#754c24' }, name: 'gw' }
		$.fn.qtip.styles.ltblue = { background: '#29abe2', tip: { color: '#29abe2' }, name: 'gw' }
		
		$(".icons .tip").qtip({
			content: {
				prerender: true
			},
			position: {
				corner: {
					target: 'topLeft',
					tooltip: 'bottomLeft'
				},
				adjust: {
					scroll: false,
					resize: false
				}
			},
			style: 'gw',
			show: {
				effect: {
					length: 0
				}
			},
			api: {
				onRender: function() {
					if (this.id == 1) {
						this.updateStyle('yellow');
					} else if (this.id == 2) {
						this.updateStyle('red');
					} else if (this.id == 3) {
						this.updateStyle('blue');
					} else if (this.id == 4) {
						this.updateStyle('orange');
					} else if (this.id == 5) {
						this.updateStyle('brown');
					} else if (this.id == 6) {
						this.updateStyle('ltblue');
					} else if (this.id == 7) {
						this.updateStyle('purple');
					}
				}
			}
		});
	}
	
	// Custom callout tooltips
	$("#find-plan-form").find(".options li").bind({
		mouseenter: function() {
			$(this).find(".product-callout").stop(false, true).fadeIn();
		},
		mouseleave: function() {
			$(this).find(".product-callout").stop(false, true).fadeOut();
		}
	});
	
	// Logos
	$(".client-logo").each(function() {
		Pixastic.process(this, "desaturate")
	});
	
	$(".client-logo").live('mouseover', function() {
		Pixastic.revert(this);
	});
	$(".client-logo").live('mouseout', function() {
		Pixastic.process(this, "desaturate")
	});
});

