// JavaScript Document
// global variables
var server = top.location.host;
var post_page = 'http://'+ server + '/v1/ecommerce.php';
var spinnerOpts = { position: 'center', hide: true, img: '/template/wait.gif' };
var add_pause =false;


$(document).ready(function() {
	
	$('.inline-eml').defuscate();
	
	$(function(){
		$('#home_content .column').equalizeBottoms();	
	});	
	
	$('#shopping_cart').find('.info').each(function() {
		bindToolTip($(this));
	});
	
	
	//////******* CATALOG MENU *************//////
	
	$('#search_form').submit(function() {
		if($.trim($('#qry').val()) == '')
			return false;
	});
	$(function() {
		$("a.top_level").click(function() { return false; });
		$(".level_2 .has-child").each(function() {
			if($(this).find('li.active').size() <= 0) {
				$(this).children('ul').hide();
			}
		});
		$(".level_2 .has-child").children('a').click(function() { 
			$(".level_2 .has-child").children('ul')
			$(this).siblings('ul').slideToggle('normal'); 
			return false; 
		});
	});
	
	//////******* CATALOG PAGINATION *************//////
	
	// run pagination if this is the first load of the page
	//initPagination();
	// run pagination if broswer back/ forward is used
		$(window).bind( 'hashchange', function(e) {
			initPagination();
				
			// if there is no active found, assume the first
			if($('.paginate').find('a.inactive').size() > 0) {
				// do nothing
			}
			else {
				var url = location.href;
				runPaginate(url);
			}
		});
		$(window).trigger( 'hashchange' );
	
	// do nothing if the current page link is clicked
	$('.paginate').find('a.inactive').click(function() {
		return false;
	});
	
	//////******* END CATALOG PAGINATION *************//////

	//////************* CATALOG SHOPPING CART *************//////
	
	// create a container to be reused for tooltip image previews
	$('body').append('<div id="cart_img_container" style="display:none;"><div class="cart_img_top"></div><div class="cart_img_bottom"></div></div>');
	
	// bind all the tools functiona to cart items
	$('.cart_item, .chkout_item').each(function() { 
		bindTools(this);
	});
	// bind the add-to-cart functions
	$('.additem').each(function() {
		$(this).bind('click',function() {
			addItemToCart($(this));
			return false;
		});
	});
	// force the user to wait while ajax is doing it's thing
	$('.additem a').click(function() { if(add_pause == false) { addItemToCart($(this).parent()); }return false; });
	
	//////************* END CATALOG SHOPPING CART *************//////
	
	//////************* ARTICLES *************//////
	$(function() {
		$("#article_nav ul").tabs("#panes > div.pane", {effect: 'fade', fadeOutSpeed: 400});
	});						   
});

/////////////////////////////////////////////////////
///////////////////  MY FUNCTIONS ///////////////////
/////////////////////////////////////////////////////

//////************* CATALOG PAGINATION *************//////
function initPagination() {
	//alert('init');
	// get the current url and find the corresponding link
	var url = location.href;
	$('.paginate').find('a').each(function() {
		href = $(this).attr('href');
		href = $(this).attr('href',href.replace('?','#')); // replace query string with a hash
		
		bindPaginate($(this)); // bind the links to the ajaxy stuff
		
		if($(this).attr('href') != url) 
			$(this).removeClass('inactive');
	});
}
// binds the ajaxy stuff to the pagination links
function bindPaginate(ele) {
	//alert('bind');
	
	$(ele).bind('click', function() {
		href = $(ele).attr('href');
		$('#product_content').fadeOut('normal');
		//runPaginate(href);
	});
}
// do the ajaxy stuff
function runPaginate(href) {
	//alert('run');
	$.ajax({
			type: 'POST',
			url: 'http://'+server+'/v1/ecommerce.php',
			data: 'func=product-page&page='+ href,
			success: function(msg){	
					$('#product_content').html(msg); 	// add the content
					ht = $('#item_list').height();		// adjust the page height
					$('#product_content').innerHeight(ht);
					
					// bind naviagtion appropriately
					$('.paginate').find('a').not('.inactive').each(function() {
						bindPaginate($(this));
					});
					$('.paginate').find('a.inactive').click(function() {
						return false;
					});
					
					// bind the cart functions to the items
					$('.additem').each(function() {
						$(this).bind('click',function() {
							addItemToCart($(this));
							return false;
						});
					});
					$('.additem a').click(function() { if(add_pause == false) { addItemToCart($(this).parent()); } return false; });
					
					$('.thumb').slimbox(); // bind the image viewer
					
					$('#product_content').fadeIn('normal'); // show the content					
				}
		});
}
//////************* END CATALOG PAGINATION *************//////

//////************* CATALOG SHOPPING CART *************//////

// binds the increment/ decrement/ remove functions to cart items
function bindTools(ele) {
	$(ele).find('a').each(function() { $(this).bind('click', function() { return false; }); });
	$(ele).find('.delitem, .delitem a').bind('click', {ele: $(ele)}, removeItem );
	$(ele).find('.incitem, .incitem a').bind('click',{ele: $(ele)},  incrementItem );
	$(ele).find('.decitem, .decitem a').bind('click', {ele: $(ele)}, decrementItem );
	
}
// run this when inventory runs down to 0
// Requires WAYFARER plugin
function outOfStock(data) {
	var soldtext = 'Sold Out';
	
	// display the item as sold out in the item list
	pid = $(data).find("pid").text();
	iid = $(data).find("id").text();
	$('#itemidx_'+pid+' .item_action').find('.cart_label').text(soldtext);
	ele = $('#i'+iid).find('a');
	txt = $(ele).text();		
	$(ele).replaceWith('<span>'+txt+'</span>');		
	$('#i'+iid).unbind().click(function() {  return false });
	$('#i'+iid).find('a').unbind().click(function() {  return false });
	$('#i'+iid).addClass('noitem').removeClass('additem');
	
	// disable the increment function in the cart and show alert
	prefix = '#cartidx_';
	if($('#checkout_cart').size() > 0) {
		prefix = '#chkoutidx_';
	}
	$(prefix+id).find('.incitem, .incitem a').unbind().bind('click',function() { return false });
	$(prefix+id).find('.incitem').addClass('clue');
	$(prefix+id).find('.clue').wTooltip({ //defaults, can be overidden 
		content: 'Sorry, we\'ve run out of this item<br/>Items already in your cart are still available.', //string content for tooltip. 
		follow: false, //does tooltip follow the cursor? 
		fadeIn: 'slow', //fade in, in milliseconds ("fast, "slow", etc may also be used) 
		fadeOut: 'slow', //fade out, in milliseconds ("fast, "slow", etc may also be used) 
		degrade: false, //if true, in IE6 tooltip will degrade to a title attribute message 
		offsetY: -50, //offsetY and offsetX properties designate position from the cursor 
		offsetX: -50, 
		style: { //the default style rules of the tooltip 
			border: "1px solid #FFD324", 
			background: "#FFF6BF",
			padding: "5px",
			height: "86px;",
			color: "#514721", 
			zIndex: "1000", 
			textAlign: "left" 
		}, 
		className: null //to style the tooltip externally, pass a className or id 
	}); 
									
}
// if items are removed from the cart, remove "Out of Stock" messages
function reStock(data) {
	var stocktext = '';
	cat = gup('c');
	
	// display the item as in stock in the item list
	pid = $(data).find("pid").text();
	iid = $(data).find("iid").text();
	$('#itemidx_'+pid+' .item_action').find('.cart_label').text(stocktext);
	ele = $('#i'+iid).find('span');
	txt = $(ele).text();		
	$(ele).replaceWith('<a href="/buy-online/'+iid+'">'+txt+'</a>');		
	$('#i'+iid).addClass('additem').removeClass('noitem');
	$('#i'+iid+',#i'+iid+' a').bind('click',function() {			
		addItemToCart($('#i'+iid));
		return false;
	});
}
// try to increment an item in the cart
function incrementItem(e) {
	href = $(e.data.ele).find('a').attr('href');
	id = gup(2,href);
	func =  'incitem';
	
	$.ajax({
		type: 'POST',
		url: post_page,
		data: 'func='+ func +'&id='+ id,
		success: function(msg){					
				flag = $(msg).find("flag").text();							
				switch(flag) {
					case '0': // there's no inventory left
						outOfStock(msg);							
						break;
					case '1': // increment the cart
						incCart(msg); 
						break;					
				}
			}
	});
	return false;
}
// try to increment an item in the cart
function decrementItem(e) {
	href = $(e.data.ele).find('a').attr('href');
	id = gup(2,href);
	func =  'decitem';
	
	$.ajax({
		type: 'POST',
		url:  post_page,
		data: 'func='+ func +'&id='+ id,
		success: function(msg){	
				container = '#shopping_cart';	
				prefix = '#cartidx_';
				total = $.trim($('#total_price_val').text());
				if(($('#total_price_val').size() <= 0) || (total == '')) {
					total = 0;
				}
				if($('#checkout_cart').size() > 0) {
					container = '#checkout_cart';
					prefix = '#chkoutidx_';
				}					
				
				if(!msg) {
					$(prefix+id).remove();
				}
				else {				
					flag = $(msg).find("flag").text();													
					if($(msg).find("restock").text() == 'true') {
						reStock(msg);							
					}	
					
					switch(flag) {
						case '1':
							decCart(msg);
							break;
						case '2':
							$(prefix+id).slideUp('normal',function() { 
								$(prefix+id).remove();
								calculateSubtotal(container);		
							});
							break;
						case '3':
							$(prefix+id).slideUp('normal',function() { 
								$(prefix+id).remove(); 
								
								if(prefix == '#cartidx_') {									
									if($('#empty-cart').size() > 0) {
										$('#empty-cart').show();
										$('#total_price_val').text('0.00');
										$('#total_price').hide();
										$('#to_checkout').hide();
										$('#cart_bottom_checkout').hide();
									}
									else {
									   $('#shopping_cart').append('<li id="empty-cart">Your Cart is Empty</li>');
										$('#total_price_val').text('0.00');
										$('#total_price').hide();
										$('#to_checkout').hide();
										$('#cart_bottom_checkout').hide();
									}	
								}
								if(prefix == '#chkoutidx_') {
									$('#checkout_cart').append('<li id="empty-cart">Your Shopping Cart is Empty. <a href="/catalog/">Continue Shopping</a></li>');
									$('#purchase_online').hide();
									$('#total_price_val').text('0.00');
								}
								
														
							});
					}
				}
		}
	});
	return false;
}
// adjust cart display when an the item in the cart is incremented
function incCart(data) {
	price = $(data).find("price").text();
	quantity = $(data).find("quantity").text();
	id = $(data).find("cartid ").text();
	quantity_left = $(data).find("quantity_left").text();
	
	if(quantity_left == '0') {
		outOfStock(data);
	}
	
	total = $.trim($('#total_price_val').text());
	if(($('#total_price_val').size() <= 0) || (total == '')) {
		total = 0;
	}	
	
	container = '#shopping_cart';	
	prefix = '#cartidx_';
	total = $.trim($('#total_price_val').text());
	if(($('#total_price_val').size() <= 0) || (total == '')) {
		total = 0;
	}
	if($('#checkout_cart').size() > 0) {
		container = '#checkout_cart';
		prefix = '#chkoutidx_';
	}
	
	$(prefix+id+' .item_action').find('.item-quantity').text(' '+quantity+' x ');
	subprice = parseFloat(quantity) * parseFloat(price);
	$(prefix+id+' .item_action').find('.item-price-val').text(subprice.toFixed(2));
	calculateSubtotal(container);
				
}
// adjust cart display when an the item in the cart is decremented
function decCart(data) {
	price = $(data).find("price").text();
	quantity = $(data).find("quantity ").text();
	id = $(data).find("cartid ").text();		
	
	container = '#shopping_cart';	
	prefix = '#cartidx_';
	total = $.trim($('#total_price_val').text());
	if(($('#total_price_val').size() <= 0) || (total == '')) {
		total = 0;
	}
	if($('#checkout_cart').size() > 0) {
		container = '#checkout_cart';
		prefix = '#chkoutidx_';
	}	
		
	$(prefix+id).find('.incitem').remove();
	$(prefix+id).find('.item_tools').prepend('<div class="incitem"><a href="/incitem/'+ id +'/">+1</a></div>');
	ele = $(prefix+id);
	$(ele).find('.incitem, .incitem a').bind('click',{ele: $(ele)},  incrementItem );
	
	$(prefix+id+' .item_action').find('.item-quantity').text(' '+quantity+' x ');
	subprice = parseFloat(quantity) * parseFloat(price);
	$(prefix+id+' .item_action').find('.item-price-val').text(subprice.toFixed(2));
	calculateSubtotal(container);
}
// remove item from the cart - either by request, or if decremented to 0
function addItemToCart(ele) {
	href = $(ele).find('a').attr('href');
	id = $(ele).attr('id').substr(1);
	itm = $(ele).parents('.product_item');	
	
	// make a copy of the item and position it
	offset = $(itm).position();
	x = offset.left;
	y = offset.top;
			
	h = $(itm).height();
	w = $(itm).width();
	
	if(add_pause == false) {
		showAddNotice(ele);
		$.ajax({
			type: 'POST',
			url: post_page,
			data: 'func=additem&id='+ id,
			dataType: 'xml',
			success: function(msg){
				randomnumber=Math.floor(Math.random()*99999999999)
				flyerid = 'flyer'+randomnumber;
				
				// build the flyer
				$('#page').append('<div id="'+flyerid+'" class="flyer"><ol></ol></div>');
				$(itm).clone().appendTo('#'+flyerid+' ol');
				$('#'+flyerid+'').find('.item_action').remove();
				$('#'+flyerid+'').css({ width: w, height: h, position: 'absolute', left: x, top: y  });
				
				// animate the flyer
				cart_ht = $('#shopping_cart').height();
				cart_pos = $('#shopping_cart').position();
				cart_top = cart_pos.top;
				cart_left = cart_pos.left;
				
				cart_w = $('#shopping_cart li').width();
				cart_h = $('#shopping_cart li').height();
				
				goto_top = cart_top + cart_ht;
				goto_left = cart_left;
				$('#'+flyerid+'').animate( { 
					left: goto_left,
					height: cart_h,
					width: cart_w}, 500, function() {
						//speed = ((y/goto_top)*500);
						$('#'+flyerid+'').animate( { 
							top: goto_top,
							height: cart_h,
							width: cart_w
							}, 500 , function() {
								$('#'+flyerid+'').remove(); 								
								flag = $(msg).find("flag").text();								
								quantity_left = $(msg).find("quantity_left").text();	
								if(quantity_left == '0') {
									outOfStock(msg);
								}
								
								switch(flag) {
									case '0':
										outOfStock(msg);							
										break;
									case '1':
										incCart(msg);
										break;
										
									case '2':
										itm = $(msg).find("itm").text();										
										$('#shopping_cart').append(itm);
										$('#product_cart').css('height','auto');
										e = $('#shopping_cart li.cart_item:last');		
										
										bindTools(e);
										bindToolTip(e.find('.info'));
										cartCounter(1);
										calculateSubtotal('#shopping_cart');
										
										$('#empty-cart').hide();
										$('#to_checkout').show();
										$('#total_price').show();
										$('#cart_bottom_checkout').show();
										
										break;
								}
								removeAddNotice(ele);
							});
					});					
			}
		});
		return false;
	}
}
// remove item from the cart - either by request, or if decremented to 0
function removeItem(e) {
	href = $(e.data.ele).find('a').attr('href');
	id = gup(2,href);
	
	$.ajax({
		type: 'POST',
		url: post_page,
		data: 'func=delitem&id='+ id,
		success: function(msg){
			
			container = '#shopping_cart';	
			prefix = '#cartidx_';
			
			total = $.trim($('#total_price_val').text());
			if($('#checkout_cart').size() > 0) {
				container = '#checkout_cart';	
				prefix = '#chkoutidx_';
			}
			$(prefix+id).slideUp('normal', function() { 														 
				$(prefix+id).remove(); 				
				calculateSubtotal(container);
				reStock(msg);				
				if($('.cart_item').size() == 0) {					
					if($('#empty-cart').size() > 0) {
						$('#empty-cart').show();
						$('#total_price_val').text('0.00');
						$('#total_price').hide();
						$('#to_checkout').hide();
						$('#cart_bottom_checkout').hide();
					}
					else {
						if(prefix != '#chkoutidx_') {
							$('#shopping_cart').append('<li id="empty-cart">Your Cart is Empty</li>');
							$('#total_price_val').text('0.00');
							$('#total_price').hide();
							$('#to_checkout').hide();
							$('#cart_bottom_checkout').hide();
						}
						else {
							$('#checkout_cart').append('<li id="empty-cart">Your Shopping Cart is Empty. <a href="/catalog/">Continue Shopping</a></li>');
							$('#purchase_online').hide();
							$('#total_price_val').text('0.00');
						}
					}
				}				
				cartCounter(0);  // update the View Cart link
			});
		}
	});
	
	return false;
}
// calculates the subtotal based on items in the cart
function calculateSubtotal(e) {
	subtotal = 0;
	$(e).find('.item-price-val').each(function() {
		subtotal = parseFloat(subtotal) + parseFloat($(this).text());
	});
	$('#total_price_val').text(subtotal.toFixed(2));
}										
// binds tooltip function to create the image preview off the cart
function bindToolTip(e) {
	$(e).tooltip({
		position: "center left", 
		offset: [0, 20],
		tip: '#cart_img_container',
		delay: 0,
		onBeforeShow: function() {
			e = this.getTrigger();
			t = this.getTip();
			
			if(e.siblings('.item_image').find('a').size() > 0) {
				img = e.siblings('.item_image').find('a').html();
			}
			else {
				img = e.siblings('.item_image').html();
			}
			html = '<div class="cart_img_top"></div><div class="cart_img_content">'+ img +'</div><div class="cart_img_bottom"></div>';
			t.html(html);	
		}		
	 });
}
// forces the user to wait while the ajax connection is working
function showAddNotice(ele) {
	$(ele).spinner(spinnerOpts);
	add_pause = true;
}
// removes the forced wait when ajax is done
function removeAddNotice(ele) {
	$(ele).spinner('remove');
	add_pause = false;
}
	
// adjust the 'View Cart' link to show the number of items in the cart
function cartCounter(dir) {
	ctr = parseInt($('#nav_cartcount').text());
	if(dir) 
		ctr++;
	else
		ctr--;		
	$('#nav_cartcount').text(ctr);	
	if(ctr != 1) 
		$('#nav_cartcount_descr').text('Items');
	else
		$('#nav_cartcount_descr').text('Item');		
}		



//////************* PLUGINS NO NEED TO EDIT BELOW *************//////

/* Wayfarer Tooltip
 * Version 1.0.6
 * Author Abel Mohler
 * URI: http://www.wayfarerweb.com/wtooltip.php
 * Released with the MIT License: http://www.wayfarerweb.com/mit.php
 */
(function(a){a.fn.wTooltip=function(f,r){f=a.extend({content:null,ajax:null,follow:true,auto:true,fadeIn:0,fadeOut:0,appendTip:document.body,degrade:false,offsetY:10,offsetX:1,style:{},className:null,id:null,callBefore:function(t,p,o){},callAfter:function(t,p,o){},clickAction:function(p,o){a(p).hide()},delay:0,timeout:0},f||{});if(!f.style&&typeof f.style!="object"){f.style={};f.style.zIndex="1000"}else{f.style=a.extend({border:"1px solid gray",background:"#edeef0",color:"#000",padding:"10px",zIndex:"1000",textAlign:"left"},f.style||{})}if(typeof r=="function"){f.callAfter=r||f.callAfter}f.style.display="none",f.style.position="absolute";var m,l,q,c,k={},b=true,e=false,n=false,s=document.createElement("div"),g=(typeof document.body.style.maxWidth=="undefined")?true:false,j=(typeof a.talk=="function"&&typeof a.listen=="function")?true:false;if(f.id){s.id=f.id}if(f.className){s.className=f.className}f.degrade=(f.degrade&&g)?true:false;for(var d in f.style){s.style[d]=f.style[d]}function i(o){if(o){if(f.degrade){a(s).html(f.content.replace(/<\/?[^>]+>/gi,""))}else{a(s).html(f.content)}}}if(f.ajax){a.get(f.ajax,function(o){if(o){f.content=o}i(f.content)})}function h(p){function t(u){if(m&&!f.content){m=null}}function o(){if(!e&&f.auto){clearInterval(c);if(f.fadeOut){a(s).fadeOut(f.fadeOut,function(){t(p)})}else{t(p);s.style.display="none"}}if(typeof f.callAfter=="function"){f.callAfter(s,p,f)}if(j){f=a.listen(f)}}if(f.timeout>0){q=setTimeout(function(){o()},f.timeout)}else{o()}}a(s).hover(function(){e=true},function(){e=false;h(k)});if(j){f.key=s;f.plugin="wTooltip";f.channel="wayfarer";a.talk(f)}i(f.content&&!f.ajax);a(s).appendTo(f.appendTip);return this.each(function(){a(this).hover(function(){var p=this;clearTimeout(q);if((this.title||this.titleMemKeep)&&!f.degrade&&!f.content){m=this.title||this.titleMemKeep;if(this.title){this.titleMemKeep=this.title;this.title=null}}if(f.content&&f.degrade){this.title=s.innerHTML}function o(){if(typeof f.callBefore=="function"){f.callBefore(s,p,f)}if(j){f=a.listen(f)}if(f.auto){var t;if(f.content){if(!f.degrade){t="block"}}else{if(m&&!f.degrade){a(s).html(unescape(m));t="block";m=null}else{t="none"}}if(t=="block"&&f.fadeIn){a(s).fadeIn(f.fadeIn)}else{s.style.display=t}}}if(f.delay>0){l=setTimeout(function(){o()},f.delay)}else{o()}},function(){clearTimeout(l);var o=this;b=true;if(!f.follow||n||(f.offsetX<0&&f.offsetY<0)){setTimeout(function(){c=setInterval(function(){h(o)},1)},1)}else{h(this)}});a(this).mousemove(function(v){k=this;if(f.follow||b){var y=a(window).scrollTop(),z=a(window).scrollLeft(),w=v.clientY+y+f.offsetY,t=v.clientX+z+f.offsetX,x=a(f.appendTip).outerHeight(),p=a(f.appendTip).innerHeight(),o=a(window).width()+z-a(s).outerWidth(),u=a(window).height()+y-a(s).outerHeight();w=(x>p)?w-(x-p):w;n=(w>u||t>o)?true:false;if(t-z<=0&&f.offsetX<0){t=z}else{if(t>o){t=o}}if(w-y<=0&&f.offsetY<0){w=y}else{if(w>u){w=u}}s.style.top=w+"px";s.style.left=t+"px";b=false}});if(typeof f.clickAction=="function"){a(this).click(function(){f.clickAction(s,this)})}})}})(jQuery);

/*
 * jQuery equalizeBottoms - v1.4 - 11/7/2009
 * http://benalman.com/projects/jquery-equalizebottoms-plugin/
 * 
 * Copyright (c) 2009 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($){$.fn.equalizeBottoms=function(a){if(isNaN(a)){a=0;this.each(function(){var b=$(this).css({height:"auto"});a=Math.max(a,b.offset().top+b.height())})}return this.each(function(){var b=$(this);b.height(a-b.offset().top)})}})(jQuery);(function($){function FloatObject(jqObj,params)
{this.jqObj=jqObj;switch(params.speed)
{case'fast':this.steps=5;break;case'normal':this.steps=10;break;case'slow':this.steps=20;break;default:this.steps=10;};var offset=this.jqObj.offset();var startpos=this.jqObj.position();this.startX=startpos.left;this.startY=startpos.top;this.currentX=offset.left;this.currentY=offset.top;this.origX=typeof(params.x)=="string"?this.currentX:params.x;this.origY=typeof(params.y)=="string"?this.currentY:params.y;this.jqObj.css({'position':'absolute','top':this.currentY,'left':this.currentX});}
FloatObject.prototype.updateLocation=function()
{this.updatedX=$(window).scrollLeft()+this.origX;this.updatedY=$(window).scrollTop()+this.origY;this.dx=Math.abs(this.updatedX-this.currentX);this.dy=Math.abs(this.updatedY-this.currentY);return this.dx||this.dy;}
FloatObject.prototype.move=function()
{if(this.jqObj.css("position")!="absolute")return;var cx=0;var cy=0;var w_ht=$(window).height();var c_ht=$(this.jqObj).height();if(this.dx>0)
{if(this.dx<this.steps/2)
cx=(this.dx>=1)?1:0;else
cx=Math.round(this.dx/this.steps);if(this.currentX<this.updatedX)
this.currentX+=cx;else
this.currentX-=cx;}
if(this.dy>0)
{if(this.dy<this.steps/2)
cy=(this.dy>=1)?1:0;else
cy=Math.round(this.dy/this.steps);if(this.currentY<this.updatedY)
this.currentY+=cy;else
this.currentY-=cy;}
if(this.currentY>this.startY){alert(this.currentY);this.jqObj.css({'left':this.currentX,'top':this.currentY});}}
$.floatMgr={FOArray:new Array(),timer:null,initializeFO:function(jqObj,params)
{var settings=$.extend({x:0,y:0,speed:'normal'},params||{});var newFO=new FloatObject(jqObj,settings);$.floatMgr.FOArray.push(newFO);if(!$.floatMgr.timer)$.floatMgr.adjustFO();if(!$.floatMgr.registeredEvents)
{$(window).bind("resize",$.floatMgr.onChange);$(window).bind("scroll",$.floatMgr.onChange);$.floatMgr.registeredEvents=true;}},adjustFO:function()
{$.floatMgr.timer=null;var moveFO=false;for(var i=0;i<$.floatMgr.FOArray.length;i++)
{FO=$.floatMgr.FOArray[i];if(FO.updateLocation())moveFO=true;}
if(moveFO)
{for(var i=0;i<$.floatMgr.FOArray.length;i++)
{FO=$.floatMgr.FOArray[i];FO.move();}
if(!$.floatMgr.timer)$.floatMgr.timer=setTimeout($.floatMgr.adjustFO,50);}},onChange:function()
{if(!$.floatMgr.timer)$.floatMgr.adjustFO();}};$.fn.makeFloat=function(params){var obj=this.eq(0);$.floatMgr.initializeFO(obj,params);if($.floatMgr.timer==null)$.floatMgr.adjustFO();return obj;};})(jQuery);function gup(position,href)
{if(!href){href=window.location.href;}
results=href.split('/');if(results==null)
return"";else
return results[position];}

/*
 * Email Defuscator - jQuery plugin 1.0-beta2
 *
 * Copyright (c) 2007 Joakim Stai
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id$
 *
 */

/**
 * Converts obfuscated email addresses into normal, working email addresses.
 *
 * @name defuscate
 * @param Boolean link If true, all defuscated email addresses will be turned into links, defaults to true (optional)
 * @param String find The regular expression used to search for obfuscated email addresses (optional)
 * @param String replace Replacement text for defuscating email addresses (optional)
 * @descr Converts obfuscated email addresses into normal, working email addresses
 */

jQuery.fn.defuscate=function(settings){settings=jQuery.extend({link:true,find:/\b([A-Z0-9._%-]+)\([^)]+\)((?:[A-Z0-9-]+\.)+[A-Z]{2,6})\b/gi,replace:'$1@$2'},settings);return this.each(function(){if($(this).is('a[@href]')){$(this).attr('href',$(this).attr('href').replace(settings.find,settings.replace));var is_link=true;}
$(this).html($(this).html().replace(settings.find,(settings.link&&!is_link?'<a href="mailto:'+settings.replace+'">'+settings.replace+'</a>':settings.replace)));});};
/*
	Slimbox v2.04 - The ultimate lightweight Lightbox clone for jQuery
	(c) 2007-2010 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/
(function(w){var E=w(window),u,f,F=-1,n,x,D,v,y,L,r,m=!window.XMLHttpRequest,s=[],l=document.documentElement,k={},t=new Image(),J=new Image(),H,a,g,p,I,d,G,c,A,K;w(function(){w("body").append(w([H=w('<div id="lbOverlay" />')[0],a=w('<div id="lbCenter" />')[0],G=w('<div id="lbBottomContainer" />')[0]]).css("display","none"));g=w('<div id="lbImage" />').appendTo(a).append(p=w('<div style="position: relative;" />').append([I=w('<a id="lbPrevLink" href="#" />').click(B)[0],d=w('<a id="lbNextLink" href="#" />').click(e)[0]])[0])[0];c=w('<div id="lbBottom" />').appendTo(G).append([w('<a id="lbCloseLink" href="#" />').add(H).click(C)[0],A=w('<div id="lbCaption" />')[0],K=w('<div id="lbNumber" />')[0],w('<div style="clear: both;" />')[0]])[0]});w.slimbox=function(O,N,M){u=w.extend({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeEasing:"swing",initialWidth:250,initialHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},M);if(typeof O=="string"){O=[[O,N]];N=0}y=E.scrollTop()+(E.height()/2);L=u.initialWidth;r=u.initialHeight;w(a).css({top:Math.max(0,y-(r/2)),width:L,height:r,marginLeft:-L/2}).show();v=m||(H.currentStyle&&(H.currentStyle.position!="fixed"));if(v){H.style.position="absolute"}w(H).css("opacity",u.overlayOpacity).fadeIn(u.overlayFadeDuration);z();j(1);f=O;u.loop=u.loop&&(f.length>1);return b(N)};w.fn.slimbox=function(M,P,O){P=P||function(Q){return[Q.href,Q.title]};O=O||function(){return true};var N=this;return N.unbind("click").click(function(){var S=this,U=0,T,Q=0,R;T=w.grep(N,function(W,V){return O.call(S,W,V)});for(R=T.length;Q<R;++Q){if(T[Q]==S){U=Q}T[Q]=P(T[Q],Q)}return w.slimbox(T,U,M)})};function z(){var N=E.scrollLeft(),M=E.width();w([a,G]).css("left",N+(M/2));if(v){w(H).css({left:N,top:E.scrollTop(),width:M,height:E.height()})}}function j(M){if(M){w("object").add(m?"select":"embed").each(function(O,P){s[O]=[P,P.style.visibility];P.style.visibility="hidden"})}else{w.each(s,function(O,P){P[0].style.visibility=P[1]});s=[]}var N=M?"bind":"unbind";E[N]("scroll resize",z);w(document)[N]("keydown",o)}function o(O){var N=O.keyCode,M=w.inArray;return(M(N,u.closeKeys)>=0)?C():(M(N,u.nextKeys)>=0)?e():(M(N,u.previousKeys)>=0)?B():false}function B(){return b(x)}function e(){return b(D)}function b(M){if(M>=0){F=M;n=f[F][0];x=(F||(u.loop?f.length:0))-1;D=((F+1)%f.length)||(u.loop?0:-1);q();a.className="lbLoading";k=new Image();k.onload=i;k.src=n}return false}function i(){a.className="";w(g).css({backgroundImage:"url("+n+")",visibility:"hidden",display:""});w(p).width(k.width);w([p,I,d]).height(k.height);w(A).html(f[F][1]||"");w(K).html((((f.length>1)&&u.counterText)||"").replace(/{x}/,F+1).replace(/{y}/,f.length));if(x>=0){t.src=f[x][0]}if(D>=0){J.src=f[D][0]}L=g.offsetWidth;r=g.offsetHeight;var M=Math.max(0,y-(r/2));if(a.offsetHeight!=r){w(a).animate({height:r,top:M},u.resizeDuration,u.resizeEasing)}if(a.offsetWidth!=L){w(a).animate({width:L,marginLeft:-L/2},u.resizeDuration,u.resizeEasing)}w(a).queue(function(){w(G).css({width:L,top:M+r,marginLeft:-L/2,visibility:"hidden",display:""});w(g).css({display:"none",visibility:"",opacity:""}).fadeIn(u.imageFadeDuration,h)})}function h(){if(x>=0){w(I).show()}if(D>=0){w(d).show()}w(c).css("marginTop",-c.offsetHeight).animate({marginTop:0},u.captionAnimationDuration);G.style.visibility=""}function q(){k.onload=null;k.src=t.src=J.src=n;w([a,g,c]).stop(true);w([I,d,g,G]).hide()}function C(){if(F>=0){q();F=x=D=-1;w(a).hide();w(H).stop().fadeOut(u.overlayFadeDuration,j)}return false}})(jQuery);

// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
	jQuery(function($) {
		$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
	});
}

/*
   Copyright (C) 2010 Corey Ballou
    Website: http://www.jqueryin.com
    Documentation: http://www.jqueryin.com/projects/spinner-jquery-preloader-plugin/

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
(function($){$.fn.spinner=function(options){var opts=$.extend({},$.fn.spinner.defaults,options);return this.each(function(){var l=0,t=0,w=0,h=0,shim=0,$s;var $this=$(this);if(options=='remove'||options=='close'){var $s=$this.data('spinner');var o=$this.data('opts');if(typeof $s!='undefined'){$s.remove();$this.removeData('spinner').removeData('opts');if(o.hide)$this.css('visibility','visible');o.onFinish.call(this);return;}}
var pos=$this.offset();w=$this.outerWidth();h=$this.outerHeight();if(h>opts.height)shim=Math.round((h-opts.height)/2);else if(h<opts.height)shim=0-Math.round((opts.height-h)/2);t=pos.top+shim+'px';if(opts.position=='right'){l=pos.left+w+10+'px';}else if(opts.position=='left'){l=pos.left-opts.width-10+'px';}else{l=pos.left+Math.round(.5*w)-Math.round(.5*opts.width)+'px';}
opts.onStart.call(this);if(opts.hide)$this.css('visibility','hidden');$s=$('<img src="'+opts.img+'" style="position: absolute; left: '+l+'; top: '+t+'; width: '+opts.width+'px; height: '+opts.height+'px; z-index: '+opts.zIndex+';" />').appendTo('body');$this.data('spinner',$s).data('opts',opts);});};$.fn.spinner.defaults={position:'right',img:'spinner.gif',height:16,width:16,zIndex:1001,hide:false,onStart:function(){},onFinish:function(){}};})(jQuery);

/*
 * jQuery BBQ: Back Button & Query Library - v1.3pre - 8/26/2010
 * http://benalman.com/projects/jquery-bbq-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,r){var h,n=Array.prototype.slice,t=decodeURIComponent,a=$.param,j,c,m,y,b=$.bbq=$.bbq||{},s,x,k,e=$.event.special,d="hashchange",B="querystring",F="fragment",z="elemUrlAttr",l="href",w="src",p=/^.*\?|#.*$/g,u,H,g,i,C,E={};function G(I){return typeof I==="string"}function D(J){var I=n.call(arguments,1);return function(){return J.apply(this,I.concat(n.call(arguments)))}}function o(I){return I.replace(H,"$2")}function q(I){return I.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")}function f(K,P,I,L,J){var R,O,N,Q,M;if(L!==h){N=I.match(K?H:/^([^#?]*)\??([^#]*)(#?.*)/);M=N[3]||"";if(J===2&&G(L)){O=L.replace(K?u:p,"")}else{Q=m(N[2]);L=G(L)?m[K?F:B](L):L;O=J===2?L:J===1?$.extend({},L,Q):$.extend({},Q,L);O=j(O);if(K){O=O.replace(g,t)}}R=N[1]+(K?C:O||!N[1]?"?":"")+O+M}else{R=P(I!==h?I:location.href)}return R}a[B]=D(f,0,q);a[F]=c=D(f,1,o);a.sorted=j=function(J,K){var I=[],L={};$.each(a(J,K).split("&"),function(P,M){var O=M.replace(/(?:%5B|=).*$/,""),N=L[O];if(!N){N=L[O]=[];I.push(O)}N.push(M)});return $.map(I.sort(),function(M){return L[M]}).join("&")};c.noEscape=function(J){J=J||"";var I=$.map(J.split(""),encodeURIComponent);g=new RegExp(I.join("|"),"g")};c.noEscape(",/");c.ajaxCrawlable=function(I){if(I!==h){if(I){u=/^.*(?:#!|#)/;H=/^([^#]*)(?:#!|#)?(.*)$/;C="#!"}else{u=/^.*#/;H=/^([^#]*)#?(.*)$/;C="#"}i=!!I}return i};c.ajaxCrawlable(0);$.deparam=m=function(L,I){var K={},J={"true":!0,"false":!1,"null":null};$.each(L.replace(/\+/g," ").split("&"),function(O,T){var N=T.split("="),S=t(N[0]),M,R=K,P=0,U=S.split("]["),Q=U.length-1;if(/\[/.test(U[0])&&/\]$/.test(U[Q])){U[Q]=U[Q].replace(/\]$/,"");U=U.shift().split("[").concat(U);Q=U.length-1}else{Q=0}if(N.length===2){M=t(N[1]);if(I){M=M&&!isNaN(M)?+M:M==="undefined"?h:J[M]!==h?J[M]:M}if(Q){for(;P<=Q;P++){S=U[P]===""?R.length:U[P];R=R[S]=P<Q?R[S]||(U[P+1]&&isNaN(U[P+1])?{}:[]):M}}else{if($.isArray(K[S])){K[S].push(M)}else{if(K[S]!==h){K[S]=[K[S],M]}else{K[S]=M}}}}else{if(S){K[S]=I?h:""}}});return K};function A(K,I,J){if(I===h||typeof I==="boolean"){J=I;I=a[K?F:B]()}else{I=G(I)?I.replace(K?u:p,""):I}return m(I,J)}m[B]=D(A,0);m[F]=y=D(A,1);$[z]||($[z]=function(I){return $.extend(E,I)})({a:l,base:l,iframe:w,img:w,input:w,form:"action",link:l,script:w});k=$[z];function v(L,J,K,I){if(!G(K)&&typeof K!=="object"){I=K;K=J;J=h}return this.each(function(){var O=$(this),M=J||k()[(this.nodeName||"").toLowerCase()]||"",N=M&&O.attr(M)||"";O.attr(M,a[L](N,K,I))})}$.fn[B]=D(v,B);$.fn[F]=D(v,F);b.pushState=s=function(L,I){if(G(L)&&/^#/.test(L)&&I===h){I=2}var K=L!==h,J=c(location.href,K?L:{},K?I:2);location.href=J};b.getState=x=function(I,J){return I===h||typeof I==="boolean"?y(I):y(J)[I]};b.removeState=function(I){var J={};if(I!==h){J=x();$.each($.isArray(I)?I:arguments,function(L,K){delete J[K]})}s(J,2)};e[d]=$.extend(e[d],{add:function(I){var K;function J(M){var L=M[F]=c();M.getState=function(N,O){return N===h||typeof N==="boolean"?m(L,N):m(L,O)[N]};K.apply(this,arguments)}if($.isFunction(I)){K=I;return J}else{K=I.handler;I.handler=J}}})})(jQuery,this);
/*
 * jQuery hashchange event - v1.3 - 7/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);
