/**
 * Main javascript file for Harwig CMS 5.3
 * @author n.vugteveen@multimove.nl
 * @version 1.0 (10-08-2011)
 * @copyright Harwig 2011
 */
$(document).ready(function(){
    /* Superfish menu, replacement for Transmenu */
	//$(".menu_level_1").addClass("sf-menu sf-vertical");
	/*$(".menu_level_1").supersubs({ 
		minWidth:    20,   // minimum width of sub-menus in em units 
		maxWidth:    20,   // maximum width of sub-menus in em units 
		extraWidth:  0,
		 animation:   {height:'show'},
		 dropShadows: false
		// extra width can ensure lines don't sometimes turn over 
	})
	.superfish({delay: 0});*/

	//make the logo clickable
	$('h1#logo, div#logo_container, div#logo_container2, h2#payoff, h1#page_title').click(function() {
		document.location = BASE_URL;
   });
	
	
	/*Enable rel="external" as a replacement for target="_blank" attributes*/
 	$("a[rel*='external']").attr('target','_blank');  
	$("a[rel=fancybox]").fancybox();
						
	if (!Modernizr.input.placeholder) {
		$("input[placeholder]").placeholder({ placeholderTextColour: "#999" });
	}
	
	$('#header_carousel').jcarousel({
		scroll: 1,
		start: 1,
		auto: 7,
	    wrap: 'last',
		initCallback: mycarousel_initCallback,
		itemVisibleInCallback: {
			onAfterAnimation: mycarousel_itemVisibleInCallbackAfterAnimation
		},
		itemVisibleOutCallback: {
            onAfterAnimation:  mycarousel_itemVisibleOutCallbackAfterAnimation
       },
	    buttonNextHTML: null,
        buttonPrevHTML: null
	});
	
	$(function($){
    	$("#twitter").tweet({
            username: "HARWIGBV",
            count: 4,
            loading_text: "loading tweets..."
        });
    });
});

function mycarousel_initCallback(carousel) {
	//Stop autoplay on hover slideshow
	$('.slideShow').bind('mouseover', function() {
		carousel.stopAuto();
	});
	$('.slideShow').bind('mouseout', function() {
		carousel.startAuto();
	});
	$('.carouselControl a').bind('click', function() {
		carousel.scroll($.jcarousel.intval(jQuery(this).attr("name")));
		return false;
	});
};

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 * Triggered after animation.
 */
function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
	$('div.' + item.id).show();
}

/**
 * This is the callback function which receives notification
 * when an item is no longer the first one in the visible range.
 * Triggered after animation.
 */
function mycarousel_itemVisibleOutCallbackAfterAnimation(carousel, item, idx, state) {
    $('div.' + item.id).hide();
};


