$(document).ready(function(){
	
		//Create vignette heading
		$("h6").wrapInner("<span></span>");
	
		//Create expandable list on members page
		$("ul.memberList li h5").click(function () {
			if ( $(this).parent().hasClass("expanded") ){
				$("ul.memberList li .content").slideUp();
				$("ul.memberList li").removeClass();
			}
			else {
				$("ul.memberList li .content").slideUp();
				$("ul.memberList li").removeClass();
				$(this).parent().children(".content").slideDown();
				$(this).parent().addClass("expanded");
			}
		});
	
		$("#OmitInvoiceAddress").click(function() {
			if ($('#OmitInvoiceAddress').attr('checked')) {
				$(".addedForm").hide();
			}
			else {
				$(".addedForm").show();
			}
		});
	
		function createCarousels(){
			//Set up central carousel on startpage
		 	jQuery("#mycarousel").jcarousel({
	            scroll: 1,
				visible: 4,
				wrap: "circular",
	            initCallback: mycarousel_initCallback,
	            // This tells jCarousel NOT to autobuild prev/next buttons
	            buttonNextHTML: null,
	            buttonPrevHTML: null
	        });	
		}
		//epi edit preview needs this delayed in order to show it in preview mode
		setTimeout(createCarousels,10);
		
		//toggle dropdown visibility
		$(".show-dropdown").click(function(e){
			e.preventDefault();
			e.stopPropagation();
			$("#dropdown-menu").slideToggle("fast");
			$("#dropdown").toggleClass("active expanded-icon");
		});
		
		//hide dropdown on click anywhere on the page
		$(document).click(function(){
			if ($("#dropdown-menu").is(':visible')) {
				$("#dropdown-menu").slideUp("fast");
				$("#dropdown").removeClass("active expanded-icon");
			}
		});
		
		//do not hide dropdown on click inside of it
		$("#dropdown-menu").click(function(e){
			e.stopPropagation();
		});

		$(".close-icon-dropdown").click(function(e){
			$("#dropdown-menu").slideToggle("fast");
			$("#dropdown").toggleClass("active expanded-icon");
			return false;
		}); 
		
		//Show expandable sidebar on starpage initially
		if($('body').hasClass('startpage')){
			$("#tab-left").addClass("active");
		}
		
		$(".tab-left-trigger").click(function(){
			$("#tab-right").removeClass("active"); 
			$("#tab-left").addClass("active"); return false;

		}); 
		$(".tab-right-trigger").click(function(){
			$("#tab-left").removeClass("active"); 
			$("#tab-right").addClass("active"); return false;
		}); 
		
		$(".close-box").click(function(){
			$("#tab-left").removeClass("active"); 
			$("#tab-right").removeClass("active"); return false;		
		}); 
	

});

	//Tip a friend functionality
	function tipFriend(url) {
		window.open(url, '', 'width=240, height=350');
	}


    function mycarousel_initCallback(carousel) {
        jQuery('.jcarousel-control a').bind('click', function() {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
            return false;
        });
    
        jQuery('.jcarousel-scroll select').bind('change', function() {
            carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
            return false;
        });
    
        jQuery('#mycarousel-next').bind('click', function() {
            carousel.next();
            return false;
        });
    
        jQuery('#mycarousel-prev').bind('click', function() {
            carousel.prev();
            return false;
        });
    }
	
	
    function mycarousel_initCallback2(carousel) {
        jQuery('.jcarousel-scroll-marketing-area select').bind('change', function() {
            carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
            return false;
        });
        jQuery('#marketing-area-next').bind('click', function() {
            carousel.next();
            return false;
        });
    
        jQuery('#marketing-area-prev').bind('click', function() {
            carousel.prev();
            return false;
        });
    }
    


