var _sitemapVisible = 0;
var _sitemapSpeed = 1000;

$(function() {

	// sitemap
	$('.sitemap-link').click(function(event) {
		event.preventDefault();
		$sitemap = $('#sitemap');
		if(!_sitemapVisible) {
			if($sitemap.length == 0) {
				$('#cn').prepend('<div id="sitemap"><img src="/umbraco/ImageGen.ashx?Font=/data/GILL.TTF&FontSize=17&FontColor=900421&BgColor=E2E2E2&text=Trafford+Housing+Trust+Website" /><div class="sitemap-container"><p class="loading">Loading...</p></div>');
				$sitemap = $('#sitemap');
				$sitemapcontainer = $('#sitemap .sitemap-container');
				$sitemap.slideDown(_sitemapSpeed);
				$sitemapcontainer.load('/sitemapservice.aspx', '', function() {
					$sitemap.slideDown(_sitemapSpeed);
				});
			}
			else {
				$sitemap.slideDown(_sitemapSpeed);
			}					
			_sitemapVisible = 1;
		}
		else {
			$sitemap.slideUp(_sitemapSpeed);
			_sitemapVisible = 0;
		}		
		
	});


	/* Suckerfish for older browsers (jQuery version) */	
	$('#nv li').hover(function() {$(this).addClass('sfhover')}, function() {$(this).removeClass('sfhover')});

	
	/* menu width adjust */
	$('#nv li > ul').each(function() {
		var w = $(this).width();
		var pw = $(this).parent().width();
		if(w < pw) {
			$(this).css({width:pw+'px'});
		}
	});
	
		
	/* rollover subnav */	
	$('#sections ul.first-level li').mouseover(function() {	
		var index = $('#sections ul.first-level li').index($(this));			
		$('#mainnav > ul').hide();
		$($('#mainnav').children()[index]).show();	
	});
	$('.navcontainer').mouseleave(function(event) {
		$('#mainnav > ul').hide();
		$('#mainnav > ul.submenu-active').show();			
	});


	$vls = $('a.video-link');
	if($vls.length > 0) {
		$('body').append('<div id="videoPlayer" class="jqmWindow" style="display:none"><img src="/images/bt-vid-close.png" class="close png"/><div class="video-container" /><div class="caption">Video caption</div></div>');
		
		$vls.click(function(event) {
			event.preventDefault();
			var title = $(this).attr('title') || 'Trafford Housing Trust';
			$('#videoPlayer .caption').html(title);
			$('#videoPlayer')
				.jqmShow()
				.find('.video-container')
					.media({
						width:     720,
						height:    425,
						autoplay:  true,
						src:       this.href,
						params:    { ShowControls: '1'}, 
						caption:   false
					});
		});

		//$.fn.media.mapFormat('mpeg', 'winmedia');
		$('#videoPlayer').jqm({
			overlay:'80', 
			closeClass:'close', 
			onShow: function(hash) { 
				hash.o.fadeIn(1000, function() { 
					hash.w.show(); 
				}); 
			},
			onHide: function(hash) { 
				var medias = hash.w.find('object');
				if(medias.length > 0) medias[0].Stop();
				hash.w.hide(); hash.o.fadeOut('1000',function() { 
					hash.w.find('.video-container').empty(); 
				});
			}
		}); 		
		
	}

});


function openCorpPlan(url) {
    var width = 780;
    var height = 580;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "subWind", windowFeatures);
    myWindow.focus();
    
}


function openCenteredSizedWindow(url, width, height) {
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "subWind", windowFeatures);
    myWindow.focus();    
}

function googleTranslateElementInit() {
    new google.translate.TranslateElement({
      pageLanguage: 'en',
      //gaTrack: true,
      //gaId: 'UA-12345-12',
      includedLanguages: 'af,sq,ar,be,bg,ca,zh-CN,zh-TW,hr,cs,da,nl,en,et,tl,fi,fr,gl,de,el,ht,iw,hi,hu,is,id,ga,it,ja,ko,lv,lt,mk,ms,mt,no,fa,pl,pt,ro,ru,sr,sk,sl,es,sw,sv,th,tr,uk,vi,cy,yi,ur',
      layout: google.translate.TranslateElement.InlineLayout.SIMPLE
    }, 'google_translate_element');
}
