var browser;
var page_id; // current page's id based on URL param
var root_parent_id; // page's root parent id
browser = navigator.userAgent;
page_id = getURLparam('page_id');
root_parent_id = '6'; // default to 6 (homepage)
$(document).ready(function() {
									
	// extra styling for top nav
	$('#nav li:last').css({border:'none'});
	//$('#nav li:last a').css({width:'71px'});
	$('#nav li').hover(function() {
		$(this).addClass('over');
	}, function () {
		$(this).removeClass('over');
	});
	$('#nav li.page-item-'+root_parent_id+' > a').css('background-color', '#397FB5'); // highlight current page in nav
	
    // adjust heights and widths
	/*$('#nav li li a').equalWidth(0);
	if (browser.indexOf('MSIE') != -1) {
		$('#gutter-wrapper, #body-wrapper').equalHeightA(12);
	} else {
		$('#gutter-wrapper, #body-wrapper').equalHeightA(0);
	}
	$('#home-tier2-left ul, #home-tier2-right').equalHeightB(-20);*/
	$('#home-tier2-left li:even').css('background-color', '#ebebeb');
	
	// bold the current sub nav page
	$('#page .copy-wrapper li.page-item-'+page_id+' > a').css({ textDecoration:'none', fontWeight:'bold' }).removeAttr('href');
	
	$('a.piclenselink').text('View as slideshow');
    
    $('a.cb_flv').colorbox({iframe:true, innerWidth: 425, innerHeight: 344});

});

jQuery.preloadImages = function() {
    for(var i = 0; i<arguments.length; i++) {
        jQuery("<img>").attr("src", arguments[i]);
    }
}

$.preloadImages('images/india-nepal-gray.jpg', 'images/india-color-nepal-gray.jpg', 'images/india-gray-nepal-color.jpg');

function getURLparam(name) { var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var tmpURL = window.location.href; var results = regex.exec( tmpURL ); if( results == null ) return ""; else return results[1]; }

$.fn.equalHeightA = function(offset) {
	tallest = 0;
	this.each(function() {
		thisHeight = $(this).height();
		if (thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	
	this.each(function() {
		$(this).height(tallest+offset);
	});
}

$.fn.equalHeightB = function(offset) {
	var maxHeight=0;
	this.each(function() {
		if (this.offsetHeight>maxHeight) {
			maxHeight=this.offsetHeight;
		}
	});
	this.each(function() {
		$(this).height(maxHeight + "px");
		if (this.offsetHeight > maxHeight) {
			$(this).height(((maxHeight - (this.offsetHeight - maxHeight)) + offset)+"px");
		}
	});
};

$.fn.equalWidth = function(offset) {
	widest = 0;
	this.each(function() {
		thisWidth = $(this).width();
		if (thisWidth > widest) {
			widest = thisWidth;
		}
	});
	
	this.each(function() {
		$(this).width(widest+offset);
	});
}

