

/* twitter module 

function juitterModule() {
	$.Juitter.start({
		searchType:"searchWord", // needed, you can use "searchWord", "fromUser", "toUser"
		searchObject:"TravelAgeWest", // needed, you can insert a username here or a word to be searched for, if you wish multiple search, separate the words by comma.
		lang:"en", // restricts the search by the given language
		live:"live-300", // the number after "live-" indicates the time in seconds to wait before request the Twitter API for updates.
		placeHolder:"juitterContainer", // Set a place holder DIV which will receive the list of tweets example <div id="juitterContainer"></div>
		loadMSG: "Loading messages...", // Loading message, if you want to show an image, fill it with "image/gif" and go to the next variable to set which image you want to use on 
		imgName: "loader.gif", // Loading image, to enable it, go to the loadMSG var above and change it to "image/gif"
		total: 3, // number of tweets to be show - max 100
		readMore: "", // read more message to be show after the tweet content
		nameUser:"image", // insert "image" to show avatar of "text" to show the name of the user that sent the tweet 
		openExternalLinks:"newWindow", // here you can choose how to open link to external websites, "newWindow" or "sameWindow"
		filter:"sex->*BAD word*,porn->*BAD word*,fuck->*BAD word*,shit->*BAD word*"  // insert the words you want to hide from the tweets followed by what you want to show instead example: "sex->censured" or "porn->BLOCKED WORD" you can define as many as you want, if you don't want to replace the word, simply remove it, just add the words you want separated like this "porn,sex,fuck"... Be aware that the tweets will still be showed, only the bad words will be removed
	});
		
	$("#juitterSearch").submit(function(){
	    $.Juitter.start({
	    	searchType:"searchWord",
	    	searchObject:$(".juitterSearch").val(),
	    	live:"live-180", // it will be updated every 180 seconds/3 minutes
	    	filter:"sex->*BAD word*,porn->*BAD word*,fuck->*BAD word*,shit->*BAD word*"
	    });
		return false;
	});		

}
*/


/* nav */
/* using superfish instead */
/*
function nav() {
		
	// show sub menu on hover
	$("#nav-items li a").mouseover(function(){
    	$(".n-sub").hide();
    	var item = $(this).siblings(".n-sub");
		var itemPositionTop = $(this).parent().position().top + 50 +"px";
		var itemPositionLeft = $("#n-home").position().left +"px";
		item.css({"top":itemPositionTop,"left":itemPositionLeft});
		item.show();
    }).mouseout(function(){
    	$(this).siblings(".n-sub").hide();
    });
        
	// keep main menu on "on" state when mouse is inside sub menu
	$(".n-sub").mouseover(function(){
    	$(this).show();
    	$(this).siblings("a").addClass("current");
    }).mouseout(function(){
    	$(this).hide();
    	$(this).siblings("a").removeClass("current");
    });

	// hide sub-menu on 
	$("#header").mouseover(function(){
    	$("body .n-sub").hide();
    }).mouseout(function(){
    });
    
}
*/



/* reposition menu */

function repositionMenu() {

	$(".sf-menu .n-sub").parent().parent().css({"top":"50px"});
	$(".sf-menu").hover(function(){
		$("#m-featured .marker").hide();
    },function(){
		$("#m-featured .marker").fadeIn(500);
    });

}



/* clear input text */

jQuery.fn.resetDefaultValue = function() {
	function _clearDefaultValue() {
		var _$ = $(this);
		if ( _$.val() == this.defaultValue ) { _$.val(""); }
	}
	function _resetDefaultValue() {
		var _$ = $(this);
		if ( _$.val() == "" ) { _$.val(this.defaultValue); }
	}
	return this.click(_clearDefaultValue).focus(_clearDefaultValue).blur(_resetDefaultValue);
};



/* slideshow modules */

function cycleModules() {

	$(".slideshow-slide").cycle({ 
		timeout: 0, 
	    fx: "scrollHorz", 
	    speed: 500, 
		prev: ".m-slideshow .prev",
		next: ".m-slideshow .next"
	 });

	$(".industry-events-slide").cycle({ 
		timeout: 0, 
	    fx: "fade", 
	    speed: 500, 
		prev: "#m-industry-events .prev",
		next: "#m-industry-events .next"
	 });

	$(".videos-slide").cycle({ 
		timeout: 0, 
	    fx: "fade", 
	    speed: 0, 
		prev: "#m-more-videos .prev",
		next: "#m-more-videos .next",
	    pager: ".pager"
	});

}



/* font resizer */

function fontResizer() {

	$(".style-s").click(function() {
		$("#main").css({"font-size":"80%","line-height":"1.5em"});
		return false;
	});
	$(".style-m").click(function() {
		$("#main").css({"font-size":"100%","line-height":"1.5em"});
		return false;
	});
	$(".style-l").click(function() {
		$("#main").css({"font-size":"120%","line-height":"1.5em"});
		return false;
	});

}



/* tabs */

function tabbedModule() {

	var tabContainers = $(".t-content");
	tabContainers.hide().filter(":first").show();
	
	$(".t-nav a").click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$(".t-nav a").removeClass("selected");
		$(this).addClass("selected");
		return false;
	}).filter(":first").click();


var tabContainers4 = $(".t-newsletter");
tabContainers4.hide().filter(":first").show();

    $(".t-news a").click(function () {
        tabContainers4.hide();
        tabContainers4.filter(this.hash).show();
        $(".t-news a").removeClass("selected");
        $(this).addClass("selected");
        return false;
    }).filter(":first").click();

	var tabContainers2 = $("#m-videos-photo .m-t-content");
	tabContainers2.hide().filter(":first").show();
	
	$("#m-videos-photo .m-t-nav a").click(function () {
		tabContainers2.hide();
		tabContainers2.filter(this.hash).show();
		$("#m-videos-photo .m-t-nav a").removeClass("selected");
		$(this).addClass("selected");
		return false;
	}).filter(":first").click();


	var tabContainers3 = $("#m-more-videos .m-t-content");
	tabContainers3.hide().filter(":first").show();
	
	$("#m-more-videos .m-t-nav a").click(function () {
		tabContainers3.hide();
		tabContainers3.filter(this.hash).show();
		$("#m-more-videos .m-t-nav a").removeClass("selected");
		$(this).addClass("selected");
		return false;
	}).filter(":first").click();

}



/* gallery */

//function gallery() {
////    $("#m-featured .m-nav li a").cycle({
////        fx: 'fade',
////        speed: 500,
////        timeout: 5000,
////        pager: '#m-featured .m-nav li a',
////        pagerEvent: 'mouseover',
////        pause: false,
////        pauseOnPagerHover: false
////    });
//	$("#m-featured .m-nav li:first").addClass("selected");	
//	$("#m-featured .m-content .item:first").show();	
//	$("#m-featured .m-nav li a").click(function() {
//			
//		//remove "selected" class & hide current item	
//		$(document).find("#m-featured .selected").removeClass("selected");
//		$(document).find(".item").hide();
//		
//		//get link, and then show selected item
//		$(this).parent().addClass("selected");
//		var getID = $(this).attr("href");
//		$(document).find(getID).fadeIn(300);
//		return false;

//});

//}



/* login popup */

function loginPopup() {

	var loginBGWidth = $(document).width() +"px";
	var loginBGHeight = $(document).height() +"px";
	var loginMargin = ($(window).width() - 600)/2 +"px";
	
	// activate login popup when "login" or "register" button is clicked
	$(".login-trigger").click(function() {
		
		//set bg dimension to cover the whole browser
		$(".login").css({"width":loginBGWidth,"height":loginBGHeight});		
		
		//set login module's position
		$(".login-container").css({"left":loginMargin});
		$(".login").fadeIn(200);
		$(".login-container").fadeIn(200);
		return false;
		
	});

	// redo functions on window resize (so the bg still covers the screen & the login module is positioned correctly)
//	$(window).resize(function() {
//		var loginBGWidth = $(document).width() +"px";
//		var loginBGHeight = $(document).height() +"px";
//		var loginMargin = ($(window).width() - 600)/2 +"px";
//		$(".login").css({"width":loginBGWidth,"height":loginBGHeight});		
//		$(".login-container").css({"left":loginMargin});
//	});
//	
//	// emulate "position:fixed" (ie6)
//	$(window).scroll(function() {
//	    $(".login-container").css("top", $(window).scrollTop() + 200 + "px");
//	});	
//	
//	// close login module when the user clicks anywhere on the body...
//	$(document).click(function() {
//		$(".login").fadeOut(200);
//		$(".login-container").fadeOut(200);
//	});
//	// ...except the login module itself
//	$(".login-container").click(function(event){
//	    event.stopPropagation();
//	});

}



/* pagination for "more videos" */

function countVideos() {

	// add "active-page" class on active li
    $(".videos-slide li").each(function() {	
		$(this).removeClass("active-page");
    	if ($(this).is(":visible")) {
			$(this).addClass("active-page");			
    	} else {
    	}
    });
    
    // add id (#) for each div in "more videos" module
   	$(".videos-slide li div").each(function(i) {
   		$(this).attr("id",i+1);
   	});
    
    // count active videos, then display it
    var countVideoFirst = $(".videos-slide li.active-page div:first").attr("id");
    var countVideoLast = $(".videos-slide li.active-page div:last").attr("id");
    var countVideosDisplayed = "Displaying " + countVideoFirst + " - " + countVideoLast + " of ";
    $(".videos-count-display").html(countVideosDisplayed);
    
    // count total # of videos, then display it
    var countVideosAll = $(".videos-slide div").size() + " videos";
    $(".videos-count-all").html(countVideosAll);

}	



/* rollover for "more destination" maps */

function rolloverMap() {

	$(".marker").hover(function(){
		$(this).find("img").fadeIn(200);
		$(this).css({'z-index':'1'});
    },function(){
		$(this).find("img").fadeOut(200);
		$(this).css({'z-index':'0'});
    });

}



/* activate all */

$(document).ready(function(){	

    jQuery('ul.sf-menu').superfish();
	repositionMenu();

	$("input#input-search").resetDefaultValue();
	$("input#input-newsletter").resetDefaultValue();
	$("input#input-newsletter-nav").resetDefaultValue();
	$(".juitterSearch").resetDefaultValue();

	cycleModules();
	fontResizer();
	tabbedModule();
	//gallery();
	//juitterModule();
	loginPopup();
	countVideos();
	rolloverMap();

	// activate again when prev/next/page links are clicked
	$(".pager").click(function(){
		countVideos();
	});
	$("#m-more-videos .prev").click(function(){
		countVideos();
	});
	$("#m-more-videos .next").click(function(){
		countVideos();
	});

});

