/* legacy */
$(document).ready(function() {
	try {
		side.Load($('div.bottom'));
		flick.SetupFlicks()
		menu.scroll('#extras-bar', 122);
	} catch (e) { }
	$('a[rel=lightbox]').attr('rel', 'prettyPhoto');
});

/* PRETTY PHOTO */
$(document).ready(function() {
	var flag = false;
	$("a[href*='.mp4'], a[href*='.flv'], a[href*='.swf'],a[href*='.png'], a[href*='.jpg'], a[href*='.gif']").not('.download').each(function(i, o) {
		$(o).attr('rel', 'prettyPhoto');
		flag = true;
	});
	if (flag == true) {
		$("a[rel^='prettyPhoto']").prettyPhoto();
	}

});

/* News hack */
$(document).ready(function() {
	NewsHack();
});

var iCalled = 0;
var NewsHack = function(aNews, sC) {
	if (iCalled == 10) { return false; }
	var sC = $('#site-selector li.active img').attr('alt');
	var aNews = $('#news-items li a');
	if (!aNews.length) { window.setTimeout('NewsHack();', 1000); return false; }
	$(aNews).each(function(i, o) {
		asNews = $(o).attr('href').split('/');
		asNews[1] = sC.toLowerCase();
		$(o).attr('href', asNews.join('/'));
	});
}

$(document).ready(function() {
	try {
		if ($.browser.msie && parseInt($.browser.version) < 8) {
			$('ol#primary-navigation>li').addClass('top');
			$('ol#primary-navigation').fadeIn(300);
			$('ol#primary-navigation>li').mouseenter(function() { $(this).removeClass('top'); $(this).addClass('topover') });
			$('ol#primary-navigation>li').mouseleave(function() { $(this).removeClass('topover'); $(this).addClass('top') });
		}
	} catch (e) { }
});


/* SITE TOGGLE */
$(document).ready(function() {
	$('#site-selector a').click(function(event) {
		event.preventDefault();
		$(this).blur();
		($(this).attr('href') == '#') ? $('#site-selector').toggleClass('open') : window.location = $(this).attr('href');
	})
});


/* SEARCH */
$(document).ready(function() {
	$('#search-box').val('Search')
	$('#search-box').attr('class', 'untouched')
	$('#search-box').click(function() {
		if ($('#search-box').attr('class') == 'untouched') {
			$('#search-box').attr('class', 'touched')
			$('#search-box').val('');
		}
	})
	$('#search-box').keydown(function(event) {
		if (event.keyCode == '13') {
			SiteSearch($('#search-box').val(), $('#site-code').val());
		} else {
			return true;
		}
	})
	$('#search-button').click(function(event) { event.preventDefault(); SiteSearch($('#search-box').val(), $('#site-code').val()) })
});

function SiteSearch(sSearch, iCode) {
	window.location = '/search-results.asp?search=' + sSearch + '&site-code=' + iCode;
}

//$(document).ready(function() {
//	$('.contact-us').hide();
//	$('#more-information').hide();
//});#


// Roadmaps
$(document).ready(function(){
	if (!$('a[href*="/_roadmap"]').length) { return; }
	$('a[href*="/_roadmap"]').prettyPhoto({changepicturecallback : function () {
		$('iframe[src*="i2group.com/_roadmap"]').contents().find('a').click(
			function(e){
				e.preventDefault();
				window.location.href = $(this).attr('href');
			});
	}});
});
