
$(document).ready(function(){

//Remove Black bg on these pages
	var widePage = [ "/signup.php", "/password-retrieve.php", "/signin.php" ];
 	if(jQuery.inArray(window.location.pathname,widePage) >= 0){
		document.getElementsByTagName("html")[0].style.background="none";
	}

//Do styled headings
	$('#content_container h1, .article h1').each(function() {

			//replace zBan corners & Split H1 tags into 2 color spans
			$('.corners-top').remove();
			var blue = $(this).html().split(' ');	
			//var grey = blue.splice(Math.round(blue.length/2), 100);	// uncomment this for half blue half grey
			var grey = blue.splice(1, 100);								// uncomment this for 1st word blue, the rest grey
			$(this).replaceWith('<h1><span class="blue">' + blue.join(" ") + '</span> <span class="grey">' + grey.join(" ") + '</span></h1>');
		
	});

//Do sIFR replacements

		var ChampagneAndLimousines = { src: '/images/ChampagneAndLimousinesv3.swf' };
		sIFR.activate(ChampagneAndLimousines);

		sIFR.replace(ChampagneAndLimousines, {
		  selector: '#feature_promo h1',
		  css: '.sIFR-root { color: #ffffff; font-size: 31px; text-transform: uppercase;padding: 0; margin: 0; }',
		  wmode : "transparent"
		});
		sIFR.replace(ChampagneAndLimousines, {
		  selector: '#content_container h1, .article h1',
		  css: '.sIFR-root {background-color: #ffffff; font-size: 28px; text-transform: uppercase; } .blue { color: #2996c6; } .grey{ color: #444444;}',
		  wmode : "transparent"
		});
		sIFR.replace(ChampagneAndLimousines, {
		  selector: '#aside H1',
		  css: '.sIFR-root {background-color: #000000; font-size: 18px; text-transform: uppercase; color: #2996c6; margin: 0;}'
		});
		
//FAQ, hover
	function makeDDslider(selector){
		$(selector)
			.find("dd").addClass("hide").hide().end()
			.find("dt").addClass("toggleOff").wrapInner("<div class=\"toga\">")
			.toggle(
				function(){ $(this).swapClass("toggleOff", "toggleOn").next("dd").slideDown("normal"); },
				function(){ $(this).swapClass("toggleOff", "toggleOn").next("dd").slideUp("normal"); }
			);
	}
	if ($("dl#faqs").get(0)) {
    	makeDDslider("dl#faqs");
	} else if ($("dl.faqs").get(0)) {
		makeDDslider("dl.faqs");
	}

//hoverBox mouse-over
	$('.hoverBox').append('<div class="close"></div>');
	$(".hoverBoxAnchor").click(function(e) {
		var hoverB = $(this).children();
		hoverB[0].style.left = "-" + ((hoverB.outerWidth()/2) - ($(this).outerWidth()/2) ) + 'px';
		hoverB[0].style.top = "-" + ((hoverB.outerHeight()/2) - ($(this).outerHeight()/2) ) + 'px';
		hoverB.show();
	});
    
	/*$('.hoverBox').mouseout(function() {
		$(this).fadeOut('fast');
	});*/
	
	$(document).click(function() {
		//$(this).parent('.hoverBox').fadeOut('fast');
		//$('.hoverBox').fadeOut('fast');
	});
	
	$('.hoverBox .close').click(function() {
		//$(this).parent('.hoverBox').fadeOut('fast');
		$('.hoverBox').fadeOut('fast');
	});

// Fisheye Carousel
	if($('div.infiniteCarousel').length != 0){
		var autoscrolling = true;
		$('.infiniteCarousel').infiniteCarousel().mouseover(function () {
			autoscrolling = false;
		}).mouseout(function () {
			autoscrolling = true;
		});
		
		setInterval(function () {
			if (autoscrolling) {
				$('.infiniteCarousel').trigger('next');
			}
		}, 2000);
	
		$('.infiniteCarousel').infiniteCarousel();
		$('div.wrapper').jqDock({ 
			align:        'middle',
			size:         110,
			distance:     200,
			coefficient : 1.5,
			labels:       false,
			duration : 200		   
	   });
	}
		
});

$.fn.swapClass = function(c1,c2) {
    return this.each(function() {
        if ($(this).hasClass(c1)) {
            $(this).removeClass(c1);
            $(this).addClass(c2);
        } else if ($(this).hasClass(c2)) {
            $(this).removeClass(c2);
            $(this).addClass(c1);
        }                    
    });
};

(function () {
    $.fn.infiniteCarousel = function () {
        function repeat(str, n) {
            return new Array( n + 1 ).join(str);
        }
        
        return this.each(function () {
            // magic!
            var $wrapper = $('> div', this).css('overflow', 'hidden'),
                $slider = $wrapper.find('> ul').width(9999),
                $items = $slider.find('> li'),
                $single = $items.filter(':first')
                
                singleWidth = $single.outerWidth(),
                visible = Math.ceil($wrapper.innerWidth() / singleWidth),
                currentPage = 1,
                pages = Math.ceil($items.length / visible);
                
            /* TASKS */
            
            // 1. pad the pages with empty element if required
            if ($items.length % visible != 0) {
                // pad
                $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
                $items = $slider.find('> li');
            }
            
            // 2. create the carousel padding on left and right (cloned)
            $items.filter(':first').before($items.slice(-visible).clone().addClass('cloned'));
            $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
            $items = $slider.find('> li');
            
            // 3. reset scroll
            $wrapper.scrollLeft(singleWidth * visible);
            
            // 4. paging function
            function gotoPage(page) {
                var dir = page < currentPage ? -1 : 1,
                    n = Math.abs(currentPage - page),
                    left = singleWidth * dir * visible * n;
                
                $wrapper.filter(':not(:animated)').animate({
                    scrollLeft : '+=' + left
                }, 500, function () {
                    // if page == last page - then reset position
                    if (page > pages) {
                        $wrapper.scrollLeft(singleWidth * visible);
                        page = 1;
                    } else if (page == 0) {
                        page = pages;
                        $wrapper.scrollLeft(singleWidth * visible * pages);
                    }
                    
                    currentPage = page;
                });
            }
            
            // 5. insert the back and forward link
            $wrapper.after('<a href="#" class="arrow back">&nbsp;</a><a href="#" class="arrow forward">&nbsp;</a>');
            
            // 6. bind the back and forward links
            $('a.back', this).click(function () {
                gotoPage(currentPage - 1);
                return false;
            });
            
            $('a.forward', this).click(function () {
                gotoPage(currentPage + 1);
                return false;
            });
            
            $(this).bind('goto', function (event, page) {
                gotoPage(page);
            });
            
            // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
            $(this).bind('next', function () {
                gotoPage(currentPage + 1);
            });
        });
    };
})(jQuery);

