// Nivo Slider
$(window).load(function() {
    $('#slider').nivoSlider({
		effect:'fade',
		effect: 'random', // Specify sets like: 'fold,fade,sliceDown'
        slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 500, // Slide transition speed
        pauseTime: 3000 // How long each slide will show
        
	});
});

// Submenu tabs
$(function() {
	$('#submenu').tabs();
});



// more or less
var Bios = {
	expand: function( obj ) {
		var shortBio = $( obj ).parent( "p.shortBio" );
		var fullBio = $( shortBio ).siblings( "p.bio" );
		$( shortBio ).hide();
		$( fullBio ).show();
	},
	contract: function( obj ) {
		var fullBio = $( obj ).parent( "p.bio" );
		var shortBio = $( fullBio ).siblings( "p.shortBio" );
		$( shortBio ).show();
		$( fullBio ).hide();
	}
}




// Featured tabs
$(function() {
    $('#featuresli').cycle({
        fx:      'scrollHorz',
        timeout:  6000,
        prev:    '#prev',
        next:    '#next',
        pager:   '#navi',
        pagerAnchorBuilder: pagerFactory

    });

    function pagerFactory(idx, slide) {
        var s = idx > 2 ? 'style="display:none"' : '';
        return '<li'+s+'><a href="#">'+(idx+1)+'</a></li>';
    };
});



		// FAQs toggle answers

    $('.roomkey-faqs-list li p').hide();
    $('.roomkey-faqs-list li > a').toggle(
      function(e){
        e.stopPropagation();
  			e.preventDefault();
        $(this).parent().find('p').slideDown();
        $(this).addClass('question-open');
    }, 
      function(e){
        e.stopPropagation();
  			e.preventDefault();
        $(this).parent().find('p').slideUp();
        $(this).removeClass('question-open');
    });



$(document).ready(function() {
 
 // Sticky Top Nav

	$('.top').addClass('hidden');
	$.waypoints.settings.scrollThrottle = 30;
	$('#wrapAll').waypoint(function(event, direction) {
		$('.top').toggleClass('hidden', direction === "up");
	}, {
		offset: '-100%'
	}).find('#nav').waypoint(function(event, direction) {
		$(this).parent().toggleClass('sticky', direction === "down");
		event.stopPropagation();
	});

// popups
		$('#videopop').popupWindow({ 
			height: 410, 
			width: 700, 
			centerBrowser: 1
		}); 
	
		$('#audiopop').popupWindow({ 
			height: 100, 
			width: 520, 
			centerBrowser: 1
		}); 
		
		$('#nl-subscribe').popupWindow({ 
			height: 500, 
			width: 700, 
			centerBrowser: 1
		}); 
		
		
		// Widgets tabs
$(function() {
	$('.wtabs').tabs();
});





});


// Itunes Style Slider

// document ready
$(document).ready(function() {
	// user settings
	siftSpeed = 7600; // how often to switch slides
	actionPause = 8800; // how long to pause if action
 
	// internal script settings
	// (do not change below here unless you know what you're doing)
	var images = $("#gallery img");
	var thumbs = $("#thumbs");
	var thumbimages = $("#thumbs img");
	var thumblinks = $("#thumbs a");
	var thumbslist = $("#thumbs ul");
	var thumbitems = $("#thumbs li");
	var index = thumbitems.length-1;
	var thumbsHeight = 87;
	var areaHeight = 348;
 
	// clone markup for thumbs to create thumbs above the last thumb
	thumbitems.slice(0, 1).clone().attr('rel', '2').appendTo(thumbslist);
	thumbitems.slice(1, 2).clone().attr('rel', '2').appendTo(thumbslist);
	thumbitems.slice(2, 3).clone().attr('rel', '2').appendTo(thumbslist);
 
	// assign css classes to images and thumbs
	for (i=0; i<thumbimages.length; i++) {
		var tdiff = (images.length - i - 1);
		//$(thumbimages[i]).addClass("thumb-"+tdiff);
		$(images[i]).addClass("image-"+tdiff);
	}
 
	// reverse the order of the thumbs
	thumbslist.children().each(function(i,li){thumbslist.prepend(li)});
 
	// run the show function to show the first image
	show(index);
 
	// run the sift function every so often
	var $timer = setInterval(function() { sift(); }, siftSpeed);
 
	function sift(num) {
		if(num) { index = num; }
		if ( index < thumbimages.length && index > 0) {index -= 1 ; }
		else { index = thumbimages.length-1 }
		show ( index );
	}
	function show(num) {
		images.fadeOut(800);
		$("img.image-"+num).stop().fadeIn(800);
		var scrollPos = (num * thumbsHeight) - areaHeight;
		if(scrollPos < 348) scrollPos = scrollPos + areaHeight;
		if (num == thumbitems.length-1 || num > thumbitems.length-4) {
		    thumbs.stop().animate({scrollTop: scrollPos+thumbsHeight}, -1).animate({scrollTop: scrollPos}, 1200);
		    // console.log("number: "+num, ", scrollPos: "+scrollPos+"+"+thumbsHeight, ", duration: -1");
		} else {
		    thumbs.stop().animate({scrollTop: scrollPos}, 1200);
		}
		// console.log("number: "+num, ", scrollPos: "+scrollPos, ", duration: 600");
	}
 
	// after the actionPause takes place start the timer again
	function resetTimer() {
	    clearInterval($timer);
	    $timer = setInterval(function() { sift(); }, siftSpeed);
	}
 
	// add onclick function to thumb links
	thumbslist.find('a').each(function(){
		$(this).click(function() {
		    var showid = $(this).attr("class");
		    // console.log("showid: "+showid, ", timer: "+$timer);
		    show(showid);
		    index = showid;
		    clearInterval($timer);
		    var $timer = setTimeout(resetTimer, actionPause);
		    return false;
		});
	});
});


