$(document).ready(function(){
	// setup menu dropdowns
	navHoverSetup();
});

$(".search_box").live("focus", function() {
	var title = $(this).attr("title");
	var query = $(this).val();

	if( query == title )
		$(this).val("");
});

$(".search_box").live("blur", function() {
	var title = $(this).attr("title");
	var query = $(this).val();

	if( query == "" )
		$(this).val(title);
});

$(".search").live("submit", function() {
	var $search_box = $(".search_box");
	var title = $search_box.attr("title");
	var query = $search_box.val();

	if( query == title )
		$search_box.val("");

});


$(".share_size .size li").live("click", function () {
	var sizeType = $(this).attr("class");
	textZoom(sizeType);
});


function navHoverSetup() {
	var isIE = $.browser.msie;
	var browserVer = $.browser.version;

	if( isIE && browserVer <= 7 ) {
		$("ul#main_nav li").hover(
			function() {
				$(this).find("ul").css("left", "0");
			}, function() {
				$(this).find("ul").css("left", "-9999px");
			});
	}
}

function textZoom(zoomTo) {
	var $colMain = $(".col_main");

	if( zoomTo != "default" ) {
		$colMain.attr("class", "col_main " + zoomTo);
	} else {
		$colMain.attr("class", "col_main");
		zoomTo = "";
	}

	// set associated cookie
	var date = new Date();
	date.setTime(date.getTime()+(365*24*60*60*1000));
	var expires = date.toGMTString();
	document.cookie = "nwtrek_text_size=" + zoomTo + "; expires=" + expires + "; path=/";
}

// Fix FOUT for font replacement (http://paulirish.com/2009/fighting-the-font-face-fout/)
(function(){
	// if firefox 3.5+, hide content till load (or 3 seconds) to prevent FOUT
	var d = document, e = d.documentElement, s = d.createElement('style');
	if(e.style.MozTransform === '') { // gecko 1.9.1 inference
		s.textContent = 'body{visibility:hidden}';
		e.firstChild.appendChild(s);
		var f = function(){s.parentNode && s.parentNode.removeChild(s);};
		addEventListener('load',f,false);
		setTimeout(f,3000);
	}
})();

//gallery nav
var imageNum = 1;

function prev(total){
    var i = 1;
    imageNum = imageNum - 1;

    if(imageNum <= 0){
        imageNum = total;
    }

    while(i <= total){
        document.getElementById('photo'+i).style.display = 'none';
        i = i+1;
    }

    document.getElementById('photo'+imageNum).style.display = '';

}

function next(total){
    var i = 1;
    imageNum = imageNum + 1;

    if(imageNum > total){
        imageNum = 1;
    }

    while(i <= total){
        document.getElementById('photo'+i).style.display = 'none';
        i = i+1;
    }

    document.getElementById('photo'+imageNum).style.display = '';


}
