jQuery.noConflict();

//jCarousel functions
function mycarousel_initCallback(carousel) {
    jQuery(".carousel-controls a").bind("click", function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
    jQuery("#home-carousel #mycarousel-controls a").bind("click", function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
    jQuery(".homeCarouselbuttonNext").click(function(event) {
    	event.preventDefault();
    	return false;
    });
    jQuery(".homeCarouselbuttonPrev").click(function(event) {
    	event.preventDefault();
    	return false;
    });
    jQuery(".testimonials-carousel-next").click(function(event) {
    	event.preventDefault();
    	return false;
    });
    jQuery(".testimonials-carousel-prev").click(function(event) {
    	event.preventDefault();
    	return false;
    });
 }

//jCarousel - highlight link in focus
 function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
    jQuery("#mycarousel-control-" + idx).addClass("mycarousel-controls-on");
    jQuery("#mycarousel-biglink-" + idx).addClass("mycarousel-biglink-on");
}

//jCarousel - de-highlight link no longer in focus
function mycarousel_itemFirstOutCallback(carousel, item, idx, state) {
    jQuery("#mycarousel-control-" + idx).removeClass("mycarousel-controls-on");
    jQuery("#mycarousel-biglink-" + idx).removeClass("mycarousel-biglink-on");    
}

jQuery(document).ready(function() {
	// make external links open in a new window - content div only
	jQuery("a").filter(function() {
        	return this.hostname && this.hostname !== location.hostname;
    	}).addClass("external").attr({target: "_blank"});

    // Watermarks
    jQuery(".watermark-email input").watermark("Email Address *", "madano-watermark");
    jQuery(".watermark-name input").watermark("Name *", "madano-watermark");
    jQuery(".watermark-organisation input").watermark("Organisation *", "madano-watermark");
    // Forward to a friend
    jQuery(".watermark-recipient-name input").watermark("Recipient's Name *", "madano-watermark");
    jQuery(".watermark-recipient-email input").watermark("Recipient's Email *", "madano-watermark");
    jQuery(".watermark-your-name input").watermark("Your Name *", "madano-watermark");
    jQuery(".watermark-your-email input").watermark("Your Email *", "madano-watermark");
    jQuery(".watermark-your-message textarea").watermark("Your Message (optional)", "madano-watermark");
    
	// Tooltips
	jQuery(".custom-tooltip:not(.right-column)").hover(function() {
		var tooltip = jQuery(document.createElement("div"));
		jQuery(tooltip).attr("id", "tooltip");
		jQuery(tooltip).append("<span>View Case Study</span>");
		jQuery(this).append(tooltip);
	},
		function() {
			jQuery("#tooltip").remove();
		});
		
	// Tooltips-right-column
	jQuery(".right-column .custom-tooltip").hover(function() {
		var tooltip = jQuery(document.createElement("div"));
		jQuery(tooltip).attr("id", "tooltip-right");
		jQuery(tooltip).append("<span>View Case Study</span>");
		jQuery(this).append(tooltip);
	},
		function() {
			jQuery("#tooltip-right").remove();
		});
		
    // Do accordion for Networking Programme
	jQuery("#accordion").accordion(({
		autoHeight: false,
		navigation: true,
		collapsible: true
	}));
	
	// Hide more than three case studies until 'read more' link clicked
	jQuery(".casestudy-listings-item.toggle").hide();
	jQuery(".case-studies-expander").click(function(event) {
		event.preventDefault();
		jQuery(".casestudy-listings-item.toggle").show();
		jQuery(".entry-content ul.casestudy-listings li.casestudy-listings-item.expand").hide();
	});
    
	jQuery("#home-carousel #mycarousel").jcarousel({
        // Configuration goes here
        scroll: 1,
        auto: 8,
	    initCallback: mycarousel_initCallback,
        buttonNextHTML: "<a title='Next' class='homeCarouselbuttonNext' href='#'>Next</a>",
        buttonPrevHTML: "<a title='Previous' class='homeCarouselbuttonPrev' href='#'>Previous</a>",
        itemFirstInCallback:  mycarousel_itemFirstInCallback,
        itemFirstOutCallback: mycarousel_itemFirstOutCallback,      
        wrap:"both"
    });
    
	jQuery("#casestudy-carousel #mycarousel").jcarousel({
        // Configuration goes here
        scroll: 1,
        auto: 8,
        initCallback: mycarousel_initCallback,
        buttonNextHTML: "<a title='Next' class='homeCarouselbuttonNext' href='#'>Next</a>",
        buttonPrevHTML: "<a title='Previous' class='homeCarouselbuttonPrev' href='#'>Previous</a>",
        itemFirstInCallback:  mycarousel_itemFirstInCallback,
        itemFirstOutCallback: mycarousel_itemFirstOutCallback,        
        wrap:"both"
    });
    
	jQuery("#testimonials-carousel-container #mycarousel").jcarousel({
        // Configuration goes here
        scroll: 2,
        auto: 12,
        initCallback: mycarousel_initCallback,
        buttonNextHTML: "<a title='Next' class='testimonials-carousel-next' href='#'>Next</a>",
        buttonPrevHTML: "<a title='Previous' class='testimonials-carousel-prev' href='#'>Previous</a>",
        itemFirstInCallback:  mycarousel_itemFirstInCallback,
        itemFirstOutCallback: mycarousel_itemFirstOutCallback,        
        wrap:"both"
    });
    
});
