(function(){
		/*
		 * jQuery Pushbox
		 * jQuery Pushbox based on the efocus PushBox class 
		 *
		 * @author Lee Boonstra, <lee.boonstra@efocus.nl>
		 * @since 15 jun 2011
		 * @version 1.0
		 * @copyright eFocus
		 *
		 * @uses jQuery 1.4.2, <http://www.jquery.com>
		 */
		$.fn.Pushbox = function(options){
			return this.each(function(){
				var opt = options || {};
				var elViewport = this;
				var duration = 0;
				var isPaused = false;
				var intAnimSource = 0;
				var arrSlides;
                
				options = {
                    'selector'          : 'li',              //set string for the correct selector
					'navigation'		: true,				// set to true for automatic creation or provide jQuery array with DOM elements, incase false override createNavSpecial
					'navigationclass'	: 'pushbox_nav',	// classname to be given to created navigation // incase navigation false this is the customn class name to search for.
					'interval'			: 5,				// interval in seconds, set to 0 to disable automatic rotation
					'transition'		: 'slide',			// 'fade', 'slide'
					'freezeonhover'		: true,				// enables pausing of automatic rotation on mouseover
					'random'			: false				// randomize the slide on startup
				};
				for(i in options) {
					if(opt[i] != undefined) {
						options[i] = opt[i];
					}
				}
                
				/*
				 * Initialize the pushbox
				 */				
				this.init = function(selector){
                    //reset old slides
                    if(arrSlides){
                        arrSlides.each(function() {
                            $(this).addClass('inactive');
                        });
                        $('.inactive').css('z-index', 10);
                    }
                    
                    //set new slides
                    if(selector) options.selector = selector;
                    arrSlides = jQuery(this).find(options.selector);

                    arrSlides.each(function() {
                        $(this).removeClass('inactive');
                    });

                    
					var arrNav = null;
					var timer = 0;
					var intTargetSlide = 0;
					
					if(options.random){
						intCurrent = getRandomSlide()	
					} else {
						intCurrent = 0;	
					}

					if(options.transition === 'fade') {
						duration = 700;
					} else if(options.transition === 'slide') {
						duration = 800;
					}
		
					if(options.navigation) {
						setDefaultNavigation();
					} else {
						setCustomNavigation();
					}

					if(options.freezeonhover) this.setPauseEvent();
                    
                    if(options.interval > 0) queueSlide();
		
					initViewport();					
				}	
				
				/*
				 * Set Random slide number
				 */
				function getRandomSlide(){
					return intSlideNr = Math.floor(Math.random()*arrSlides.length);
				}
				
				/*
				 * Queues next slide with give interval
				 */
				function queueSlide(){
					timer = setTimeout(jQuery.proxy(function(){
						elViewport.showSlide("next");
					}, this), options.interval * 1000);
				}
				
				/*
				 * Set pause event on hover
				 */
                this.setPauseEvent = function(blnSetter){

                    if(blnSetter){
                        jQuery(arrSlides).clearQueue();
                        if(timer) clearTimeout(timer);
                        isPaused = true;
                    }

                    jQuery($('div.requestform')).bind({
                        'mouseleave' : jQuery.proxy(function() {
                            isPaused = false;
                            queueSlide();
                        }, this)
                    });

					jQuery(elViewport).bind({
						'mouseenter' : jQuery.proxy(function(event) {
							jQuery(arrSlides).clearQueue();
							if(timer) clearTimeout(timer);
							isPaused = true;
						}, this),

						'mouseleave' : jQuery.proxy(function() {
							isPaused = false;
							queueSlide();
						}, this)
					});
				}
				
				/*
				 * Set required styles on viewport element and slide elements
				 */
				function initViewport(){					
					var arrImg = $(arrSlides).find('img');
					
					/*
					 * Get the max height and width of the slide show
					 * Based on the size of the images.
					 */
					function getMaxSlideShowSize(arr){
						var objSize = new Object();
						objSize.height = 0;
						objSize.width = 0;
						
						arr.each(function(){
							var img = $(this);
							if(img[0].height > objSize.height) objSize.height = img[0].height;
							if(img[0].width > objSize.width) objSize.width = img[0].width;
						});
						return objSize;
					}
					
					var objSize = getMaxSlideShowSize(arrImg);
					
					jQuery(elViewport).css({
						'height' : objSize.height,
						'overflow': 'hidden',
						'position' : 'relative',
						'width' : 	objSize.width
					});
					
					arrSlides.css({
						'position'	: 'absolute',
						'left'		: 0,
						'top'		: 0,
						'z-index'	: 10
					});
					
					jQuery(arrSlides[intCurrent]).css({
						'z-index'	: 20
					});					
				}
				
				/*
				 * Create default navigation
				 */
				function setDefaultNavigation(){
					
					if(jQuery($('.'+options.navigationclass))){
						jQuery($('.'+options.navigationclass)).remove();
					}
					
					var elNavContainer = jQuery('<ul>').appendTo(elViewport);
					elNavContainer.wrap('<div class=' + options.navigationclass + '/>');
					
					elNavContainer.css({
						'position' : 'absolute',
						'z-index' : 9999
					});
		
					arrSlides.each(function(intIndex, elSlide) {
						var listItem = document.createElement("li");
						var linkItem = document.createElement("span");

						jQuery(listItem).addClass("nav"+(intIndex+1));
						jQuery(linkItem).html(intIndex+1);
						
						jQuery(linkItem).appendTo(listItem);
						jQuery(listItem).appendTo(elNavContainer);
					});
					
					arrNav = jQuery(elNavContainer).children('li');
					initNavigation();
				}
				
				/*
				 * Set custom navigation
				 */
				function setCustomNavigation(){
					arrNav = jQuery(options.navigationclass).children('li');
					initNavigation();
				}
					
				/*
				 * Start navigation
				 * Checks if navigation matches number of slides and adds behavior to navigation elements
     			 * otherwise, remove navigation
				 */
				function initNavigation(){
					
					if(arrSlides.length != arrNav.length) {
						arrNav.remove();
						return false;
					}
						
					arrNav.each(jQuery.proxy(function(index, item){
						jQuery(item).click(jQuery.proxy(function(){
							if(index != intCurrent) elViewport.showSlide(index);
						}, this));
					}, this));
					
					updateNavigation(intCurrent);
				}
				
				/*
				 * Update navigation item
				 * @param int index number of new slide
				 */
				function updateNavigation(intNewSlide){
					intCurrent = intNewSlide;
					
					if(arrNav) {
						arrNav.removeClass('active');
						jQuery(arrNav[intCurrent]).addClass('active');
					}
				}
				
				/*
			     * Show given slide with optional transition
			     * @param mixed string or number - 'prev', 'next' or index number
			     */
				//function showSlide(slide){
                this.showSlide = function(slide){
					if(timer) clearTimeout(timer);
					intAnimSource = jQuery(elViewport).innerWidth();
					
					if(typeof(slide) === 'number') {
						intTargetSlide = parseInt(slide);
					} else {
						if (slide === 'next') {
							intTargetSlide = getNext();
						} else if (slide === 'prev') {
							intAnimSource = -intAnimSource;
							intTargetSlide = getPrev();
						}
					}
					
					jQuery(arrSlides[intTargetSlide]).stop();
					jQuery(arrSlides[intTargetSlide]).clearQueue();
									
					if (options.transition === 'slide') setSlideAnimation();
					if (options.transition === 'fade') setFadeAnimation();
					
				}
				
				/*
				 * Get next slide number
				 */
				function getNext(){
					var intNext = 0;
					if(intCurrent < arrSlides.length - 1) {
						intNext = intCurrent + 1;
					}
					
					return intNext;
				}
				
				/*
				 * Get prev slide number
				 */
				function getPrev(){
					var intPrev = arrSlides.length - 1;
					if(intCurrent > 0) {
						intPrev = intCurrent - 1;
					}
					return intPrev;			
				}
				
				/*
				 * Set pushbox slide animation
				 */
				function setSlideAnimation(){
					jQuery(arrSlides[intTargetSlide]).css('left', intAnimSource);
					jQuery(arrSlides[intTargetSlide]).css('z-index', 20);
					jQuery(arrSlides[intCurrent]).css('z-index', 15);

					jQuery(arrSlides[intTargetSlide]).animate({'left' : 0},	{
						'duration'	: duration,
						'complete'	: jQuery.proxy(function(){
							jQuery(arrSlides[intCurrent]).css({
								'z-index'	: 10
							});
							updateNavigation(intTargetSlide);
							if(!isPaused) queueSlide();
						}, this)
					});					
				}
				
				/*
				 * Set pushbox fade animation
				 */
				function setFadeAnimation(){
					jQuery(arrSlides[intTargetSlide]).css('opacity', 0);
					jQuery(arrSlides[intTargetSlide]).css('z-index', 20);
					jQuery(arrSlides[intCurrent]).css('z-index', 15);
					
					jQuery(arrSlides[intTargetSlide]).animate({'opacity' : 1},	{
						'duration'	: duration,
						'complete'	: jQuery.proxy(function(){
							jQuery(arrSlides[intCurrent]).css({
								'z-index'	: 10
							});
							updateNavigation(intTargetSlide);
							if(!isPaused) queueSlide();
						}, this)
					});					
				}
               
                //call this function outside the script.
               this.init();
                
			});
		};
})(jQuery);


/*
 * extra tabs for pushbox 
 * 
 * @author Phi Son Do, <phison.do@efocus.nl>
 * @since 27 oktober 2011
 * @uses jQuery
 */
function initPushbox(){
	this.pushbox = jQuery('.pushbox').Pushbox({
    	//selector: 'li.request-form-halls',
        selector: 'li',
        navigation: true,
    	interval: 5,
    	transition: 'fade'
    });
	var self = this;
	
	//pushbox switch		
	var tabsRequestForm = $('.requestform');
	$('.formcontent', tabsRequestForm).hide();
	
	$(".form-tabs li:first").addClass("active").show();
	$(".formcontent:first").show();
	
	$(".form-tabs li").click(function(e) {
		e.preventDefault();
		
		$(".form-tabs li").removeClass("active");
		
		$(this).addClass("active");
		$(".formcontent").hide();

		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn();
		
		//enable slide with classname request-form-***
		var classname = activeTab.split('#')[1];
		
		if (classname == "request-form-rooms") {
            self.pushbox[0].showSlide(3);
            self.pushbox[0].setPauseEvent(true);
		}
		
		if (classname == "request-form-halls") {
            self.pushbox[0].showSlide(0);
            self.pushbox[0].setPauseEvent(true);
		}

	});
}
