// Scripts -  BCdeKits.nl
// Author: Niels van Berkel - niels@van-berkel.net


// SLIDER
$(window).load(function() {
    $('#slider').nivoSlider({
        effect: 'sliceDown', // Specify sets like: 'fold,fade,sliceDown'
        slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 900, // Slide transition speed
        pauseTime: 7000, // How long each slide will show
        startSlide: 0, // Set starting Slide (0 index)
        directionNav: false, // Next & Prev navigation
        directionNavHide: true, // Only show on hover
        controlNav: false, // 1,2,3... navigation
        controlNavThumbs: false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel: false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav: true, // Use left & right arrows
        pauseOnHover: false, // Stop animation while hovering
        manualAdvance: false, // Force manual transitions
        captionOpacity: 0.8, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        randomStart: false, // Start on a random slide
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded
    });
});


// COLORBOX
$(document).ready(function(){
	$(".foto").colorbox({
		slideshow: false, 
		arrowKey: false,
		transition: 'elastic',
		maxWidth: '90%', 
		maxHeight:'90%',
		rel: 'gallery'
	});
	
	$(".youtube").colorbox({iframe:true, innerWidth:720, innerHeight:405});
});


// IMAGE RESIZE SETTINGS
$(function() {
	$( ".nieuws-samenvatting img, .nieuws-content img" ).aeImageResize({  height: 410, width: 546 });
});


// WEBPLAYER
var YWPParams = {
	volume: 0.5,
	defaultalbumart: 'http://www.bcdekits.nl/images/bcdekits/logo_player.jpg'
};


// TELLER
$(function () {
	var austDay = new Date(2013, 2 - 1, 12, 14, 0, 0);
	$('#teller').countdown({until: austDay});
});


// FADER FOTOS
$(function() {
	// DEFAULT
	$("#main a img, #sidebar a img, #footer a").css("opacity","0.8");
 
	// MOUSE OVER
	$("#main a img, #sidebar a img, #footer a").hover(function () {
 
	$(this).stop().animate({
	opacity: 1.0
	}, "slow");
},

	// MOUSE OUT
	function () {
 
	$(this).stop().animate({
	opacity: 0.8
	}, "slow");
	});
});


// MARQUEE

$(function () {
    // basic version is: $('div.demo marquee').marquee() - but we're doing some sexy extras
    
    $('p.sponsors marquee').marquee('pointer').mouseover(function () {
        $(this).trigger('stop');
    }).mouseout(function () {
        $(this).trigger('start');
    }).mousemove(function (event) {
        if ($(this).data('drag') == true) {
            this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
        }
    }).mousedown(function (event) {
        $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
    }).mouseup(function () {
        $(this).data('drag', false);
    });
});


// IFRAME HEIGHT
function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 35;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);	
}


// IMAGE RESIZER
(function( $ ) {

  $.fn.aeImageResize = function( params ) {

    var aspectRatio = 0
      ,	isIE6 = $.browser.msie && (6 == ~~ $.browser.version)
      ;

    if ( !params.height && !params.width ) {
      return this;
    }

    if ( params.height && params.width ) {
      aspectRatio = params.width / params.height;
    }

    return this.one( "load", function() {
      this.removeAttribute( "height" );
      this.removeAttribute( "width" );
      this.style.height = this.style.width = "";

      var imgHeight = this.height
        , imgWidth = this.width
        , imgAspectRatio = imgWidth / imgHeight
        , bxHeight = params.height
        , bxWidth = params.width
        , bxAspectRatio = aspectRatio;
				
      if ( !bxAspectRatio ) {
        if ( bxHeight ) {
          bxAspectRatio = imgAspectRatio + 1;
        } else {
          bxAspectRatio = imgAspectRatio - 1;
        }
      }

      if ( (bxHeight && imgHeight > bxHeight) || (bxWidth && imgWidth > bxWidth) ) {

        if ( imgAspectRatio > bxAspectRatio ) {
          bxHeight = ~~ ( imgHeight / imgWidth * bxWidth );
        } else {
          bxWidth = ~~ ( imgWidth / imgHeight * bxHeight );
        }

        this.height = bxHeight;
        this.width = bxWidth;
      }
    })
    .each(function() {

      if ( this.complete || isIE6 ) {
        $( this ).trigger( "load" );
      }
    });
  };
})( jQuery );
