/*
 *
 *  Apply more complex CSS styles and event behaviors via jQuery
 *
 */
 
(function($){
	$(function(){
		// Important! Menu drop-down fix for iDevices
		if(navigator.userAgent.toLowerCase().match(/(iphone|ipod|ipad)/)){
			$(".menu-item a").click(function(){
				if (jQuery(this).attr("href")==undefined){
					jQuery(this).next().toggle();
				}
			}).focusout(function(){
				if (jQuery(this).attr("href")==undefined){
					jQuery(this).next().hide();
				}
			});
		}

		// Event behaviors
		$("#logo").click(function(){
			window.location = $("#footer a:contains(Home)").attr("href");
		});
		
		// Complex CSS styles
		$(".dropdown ul li:first").css("padding-left","8px");
		
		// Fill out the event name for the event form
		jQuery('input[name="event-name"]').val(window.document.title).hide();
		
		// Turn off shopping cart for now (keep #id to dislay products logo)
		if (String(window.location).indexOf('products')==-1) {
			//$("#cart").hide();
		}
                
                // Hide h3 and dotted product bar of product listings that contain 'upgrades'
                $('div.page-store div.post h3:contains(" Upgrade")').hide().parent().prev().hide();
                
                // Float the ajaxcart eShop widget
                $('div.ajaxcart').css('position','relative');
                $(window).scroll(function(){
                    var t = $(window).scrollTop();
                    t = t - ($('div.ajaxcart').height() * .85);
                    if (t < 0) t = 0;
                    $('div.ajaxcart').clearQueue().animate({
                        'speed':'fast',
                        'top':t
                    });
                });
	});
})(jQuery);
