
/****************************************************************************************
									CLASS
****************************************************************************************/
var index_js = function () {
    this.init();
};


/****************************************************************************************
									INIT
****************************************************************************************/
//this only happens once in the life of the object
index_js.prototype.init = function () {
	this.mutex = false;
	//Initialization
	this.listeners();
	this.start();
};


/****************************************************************************************
									START
****************************************************************************************/
//this happens everytime the html is fully loaded and is ready
//to receive events
index_js.prototype.start = function () {
	//self
	var self = this;

};


/****************************************************************************************
									LISTENERS
****************************************************************************************/
index_js.prototype.listeners = function () {
	
	
	$('#velo, #cancelButton').click( function(){
		$('#loginOverlay').hide();
		$('#velo').hide();
	});
	
	
};




/****************************************************************************************
									OBJECT
****************************************************************************************/
var index_object;

/****************************************************************************************
									ON READY
****************************************************************************************/
//this will only happen once because js scripts are only loaded once
$(document).ready(function(){
	index_object = new index_js();
});



/****************************************************************************************
									CLASS
****************************************************************************************/
var wangle_js = function () {
	//functions that will only happen once 
	//in the life of the object
	
    this.init();
};



/****************************************************************************************
									INIT
****************************************************************************************/
//this only happens once in the life of the object
wangle_js.prototype.init = function () {
	this.loaded = false;
	this.mutex = false;
	this.navigationMenu_inside=false;
	this.navigation_lastEntered='none'; // 'photography' || 'video' || 'market' || 'blog' ||  'mission'
	this.navigation_lastLeft='none'; // 'photography' || 'video' || 'market' || 'blog' ||  'mission'
	this.menu_mutex=false;
	this.menu_inside=false;
	this.liveEvents();
	this.listeners();
	this.start();
};


/****************************************************************************************
									START
****************************************************************************************/
//this happens everytime the html is fully loaded and is ready
//to receive events
wangle_js.prototype.start = function () {
	//self
	var self = this;
	if (!Modernizr.video) {
		alert("Sorry, you will need to update your browser to a newer version!\n http://www.google.com/chrome \n http://www.mozilla.com/en-US/firefox/");
	}
		
	this.cssBrowserChanges();
	this.musicPlayer();
	// $('#photoContent,#videoContent,#marketingContent,#missionContent,#blogContent').hide();
	self.enterMenu($('#connectMenu'));
	self.enterMenu($('#musicMenu'));
	self.enterMenu($('#clientButton'));
	var t = setTimeout(function(){
		self.leaveMenu($('#musicMenu'));
		self.leaveMenu($('#clientButton'));
		self.leaveMenu($('#connectMenu'));
	},3000);
	
	var height = (($('body').height() - 600)/2) +'px';
	var width = ($('body').width() - 1000)/2 +'px';
	$('#missionContent').css('margin-left',width);
	$('#missionContent').css('margin-top',height);
	
	if ($.browser.webkit){
		$('#coverBottom').css('top','60.6%');
		$('#coverTop').css('bottom','39.6%');
	}
	if ($.browser.msie){
		$('#coverTop').css('bottom','39.8%');
		$('#coverBottom').css('top','60.3%');
	}
	
	
};



/****************************************************************************************
									LISTENERS
****************************************************************************************/
wangle_js.prototype.listeners = function () {
	//self
	var self = this;
	
	$('#leafDiv').click( function(){
		$('#greenDiv').fadeIn('fast');
		//alert(self.inside_green);
	});
	
	$('#greenDiv').mouseout(function(){
		$('#greenDiv').fadeOut('fast');
		self.inside_green = false;
		$('.menu').trigger('mouseleave');
	});
	
	$('#mailButton').click( function(){
		$.ajax({
				url: 'contact/',
				type: 'GET',
				data:{
				},
				success: function(data){
					$('#contactOverlay').html(data);
				},
				complete: function(data)
				{
					$('#velo').show();
					$('#contactOverlay').show();
				}
			});	
	});
	
	$('#contactSubmit').live('click',function(){
		$.ajax({
			url: 'contact/',
			type: 'POST',
			data:{
				topic: $('#contactSubject').val(),
				message: $('#contactMessage').val(),
				email: $('#contactEmail').val(),
				name: $('#contactName').val(),
			},
			success: function(data){
				$('#contactOverlay').html(data);
			},
			complete: function(data)
			{
				$('#velo').show();
				$('#contactOverlay').show();
				if ($('#contactThank').html() != ""){
					hideInterval = window.setInterval(function(){
						$('.overlay').hide();
						$('#velo').hide();
					}, 3000);
				}
			}
		});	
	});
	
	$('#clientLogged').click( function(){
		var logged = $('#clientLoggMessage').html();
		if (logged == 'client'){
			$.ajax({
				url: 'login/',
				type: 'GET',
				data:{
				},
				success: function(data){
					$('#loginOverlay').html(data);
				},
				complete: function(data)
				{
					$('#velo').show();
					$('#loginOverlay').show();
				}
			});	
		}else{
			$.ajax({
				url: '/',
				type: 'POST',
				data:{
					logout: "true"
				},
				success: function(data){
					$('#clientLoggMessage').html('client');
					window.location = "/";
				},
			});	
		}
		
	});
	
	$(window).resize(function() {
		//console.log('screen resolution: '+ window.screen.width +"x"+window.screen.height);
		var height = (($('body').height() - 600)/2) +'px';
		var width = ($('body').width() - 1000)/2 +'px';
		$('#missionContent').css('margin-left',width);
		$('#missionContent').css('margin-top',height);
		try{
			self.cssBrowserChanges();
		}catch(err)
		{
		  //console.log('error in base.js - cssBrowserChanges :'+err);
		}
	});
	
	$('#velo').click( function(){
		$('.overlay').hide();
		$('#velo').hide();
	});
		
	
	$('.navigationButton').click(function(){
		var name = $(this).attr('id').split('B')[0];
		if(name!='video'){
			try
			{
				video_object.pauseVideo();
				//console.log('pause video');
			}
			catch(err)
			{
			  //console.log('error in base.js - pauseVideo :'+err);
			}
		}
		//Download button only appears in the Photography 
		$('#downloadPhotos').hide();
		if(name=='blog'){
			$('.content').hide();
			$('#blogContent').show();
		}else if(name=='mission'){
			$('.content').hide();
			$('#missionContent').show();
		}else{
			self.getSecction(name);
		}

	});
	
	// Navigation
	$('.navigationButton').bind('mouseenter', function(event) {
		self.enterNavigation($(this));
	});
	$('.navigationButton').bind('mouseleave', function(event) {
		self.leaveNavigation($(this));
	});
	
	$('#navigationMenu').bind('mouseenter', function(event) {
		self.navigationMenu_inside=true;
	});
	$('#navigationMenu').bind('mouseleave', function(event) {
		self.navigationMenu_inside=false;
	});
	
	// Menu
	$('.menu').bind('mouseenter', function(event) {
		self.enterMenu($(this));
	});
	
	
	$('.menu').bind('mouseleave', function(event) {
		self.leaveMenu($(this));
	});
	
	

	// Initial animation
	$('.navBarButton').bind('mouseenter',function(){
		$('.content').stop().css('opacity','1').hide();
		if($(this).attr('id')=='photographyIndexButton'){
			$('#coverRight').css('margin-left','-150px');
			$('#coverLeft').css('margin-right','250px');
			//$('.content').hide(); //fadeOut in mouseleave does the same.
			$('#photoContent').show();
			photo_object.showFirstOnly();
		}else if($(this).attr('id')=='videoIndexButton'){
			$('#coverRight').css('margin-left','-50px');
			$('#coverLeft').css('margin-right','150px');
			$('#videoContent').show();
		}else if($(this).attr('id')=='missionIndexButton'){
			$('#coverRight').css('margin-left','150px');
			$('#coverLeft').css('margin-right','-50px');
			//$('.content').hide();
			$('#missionContent').show();
		}else if($(this).attr('id')=='marketingIndexButton'){
			$('#coverRight').css('margin-left','50px');
			$('#coverLeft').css('margin-right','50px');
			//$('.content').hide();
			$('#tab1,#marketingContent').show();
		}else if($(this).attr('id')=='blogIndexButton'){
			$('#coverRight').css('margin-left','250px');
			$('#coverLeft').css('margin-right','-150px');
			//$('.content').hide();
			$('#blogContent').show();
		}
		$(this).children('.navBarButtonImg').hide();
		$(this).children('.navBarButtonImgActive').stop().css('opacity','1').show().animate({'marginTop':'-10px','marginLeft':'-10px'},200);
	});
	
	$('.navBarButton').bind('mouseleave',function(){
		var elem = $(this);
		$('#logo').hide();
		$(this).children('.navBarButtonImgActive').stop().animate({'marginTop':'0px','marginLeft':'0px'},200,function(){
			$(elem).children('.navBarButtonImgActive').fadeOut(300);
			$(elem).children('.navBarButtonImg').fadeIn(400);
			if($(elem).attr('id')=='photographyIndexButton'){
				$('#photoContent').hide();
			}else if($(elem).attr('id')=='videoIndexButton'){
				$('#videoContent').hide();
			}else if($(elem).attr('id')=='blogIndexButton'){
				$('#blogContent').hide();
			}else if($(elem).attr('id')=='marketingIndexButton'){
				$('#marketingContent').hide();
			}else if($(elem).attr('id')=='missionIndexButton'){
				$('#missionContent').hide();
			}
		});
	});
	
	$('.navBarButton').click(function(){
		$('.navBarButton').unbind('mouseenter').unbind('mouseleave');
		$('.navBarButton').children('.navBarButtonImgActive').hide();
		$('#navBar').hide();
		$('.navBarButton').children('.navBarButtonImg').show();
		$('#logo').show().css('z-index','10');
		$('#logo').animate({'bottom':'0%','marginBottom':'-170px'},2000,function(){
			$('#logo').fadeOut();
			$('#navigationMenu').fadeIn();
		});
		$('#logoBottom').fadeOut();
		$('#coverTop').animate({"height":"0"},2000,function(){
			
		});
		$('#coverBottom').animate({'top':'100%','marginTop':'0px'},2000,function(){
			
		});
		$('#coverLeft').animate({'width':'0'},2000,function(){
			
		});
		$('#coverRight').animate({'left':'100%'},2000,function(){
			
		});
		
		
		if($(this).attr('id')=='photographyIndexButton'){
			self.getSecction('photography');
		}else if($(this).attr('id')=='videoIndexButton'){
			self.getSecction('video');
		}else if($(this).attr('id')=='missionIndexButton'){

		}else if($(this).attr('id')=='marketingIndexButton'){
			self.getSecction('marketing');
		}else if($(this).attr('id')=='blogIndexButton'){

		}
		
	});
	
	
	$('#phoneLink').click(function(){
		if ($('#phoneForm').css('display')=='none'){
			$('#phoneForm').show();
		}else{
			$('#phoneForm').hide();
		}
	});
		
};



/****************************************************************************************
									CSS BROWSER CHANGES
****************************************************************************************/

wangle_js.prototype.cssBrowserChanges = function () {

	var self = this;
	var width = $(window).width() * 1;
	var height = $(window).height() * 1;
	//alert("new resolution: "+ $(window).width()+"x"+$(window).height());
	if (width <1280){
		$('#navBar').css('margin-bottom','92px');
		$('#logoBottom').css('margin-bottom','-2px');
	}else if((width>=1280) && (width < 1408)){
		$('#navBar').css('margin-bottom','96px');
		$('#logoBottom').css('margin-bottom','2px');
	}else if((width>=1408) && (width < 1600)){
		if ($.browser.webkit){
			$('#logoBottom').css('margin-bottom','3px');
		}else{
			$('#navBar').css('margin-bottom','96px');
			$('#logoBottom').css('margin-bottom','1px');
		}
	}else if((width>=1600) && (width < 1813)){
		$('#coverTop').css('margin-bottom','175px');
		$('#coverBottom').css('margin-bottom','-76px');
		$('#logoBottom').css('margin-bottom','2px');
	}else{
		if ($.browser.webkit){
			$('#coverTop').css('margin-bottom','170px');
			$('#coverBottom').css('margin-bottom','-70px');
		}else{
			$('#coverTop').css('margin-bottom','173px');
			$('#coverBottom').css('margin-bottom','-73px');
			$('#logoBottom').css('margin-bottom','2px');
		}
	}
};


/****************************************************************************************
									GET SECCTION
****************************************************************************************/
wangle_js.prototype.getSecction = function (name) {
	
	//alert("calling getSection2");
	$.ajax({
		url: '/'+name+'/',
		type: 'POST',
		dataType: 'json',
		data:{
		},
		beforeSend:function(){
			//alert("before");
			if(self.mutex)
				return false;
			self.mutex=true;
		},
		error:function(xhr, status, errorThrown) { 
            alert(errorThrown+'\n'+status+'\n'+xhr.statusText); 
        }, 
		success: function(data){
			//alert("1111");
			// $('#content').html(data);
			$('.content').hide();
			//jquery html doesn't work in IE
			if ($.browser.msie){
				alert("IE");
				if(name=='photography'){
					$('#photoMenu').empty();
					$('#originalPhotos').empty();
					$('#photoMenu').append(data['photoMenu']);
					$('#originalPhotos').append(data['originalPhotos']);
					$('#downloadPhotos').show();
				}else if(name=='video'){
					$('#videoMenu').empty();
					$('#videoMenu').append(data['videoMenu']);
				}else if(name=='marketing'){
					$('#marketingContent').empty();
					$('#marketingContent').append(data['marketing']);
				}
			}else{
				if(name=='photography'){
					$('#photoMenu').html(data['photoMenu']);
					$('#originalPhotos').html(data['originalPhotos']);
					$('#downloadPhotos').show();
				}else if(name=='video'){
					$('#videoMenu').html(data['videoMenu']);
				}else if(name=='marketing'){
					$('#marketingContent').html(data['marketing']);
				}
			}
		},
		complete: function(){
			//alert("2222");
			if(name=='photography'){
				photo_object.start();
				photo_object.listeners();
			}else if(name=='video'){
				video_object.start();
				$('#videoContent').show();
				video_object.listeners();
			}else if(name=='marketing'){
				marketing_object.start();
				marketing_object.listeners();
			}
			//freed the mutex
			self.mutex=false;
		}
	});
};

/****************************************************************************************
									MUSIC PLAYER
****************************************************************************************/
wangle_js.prototype.musicPlayer = function () {
	$(function() { // executed when $(document).ready()
		  $("#jpId").jPlayer( {
			ready: function () {
			var songName =	$('#songName').html().trim();
			  this.element.jPlayer("setFile", "/static/music/"+ songName);
			  this.element.jPlayer("volume", 50);
			  // this.element.jPlayer("play");
			},
			swfPath: "/static/js/"
			}).jPlayer("onSoundComplete", forwardSong);
	});
	
	currentSong = 1;
	volume = 50;
	numSongs = $('#numSongs').html();
	
	function changeSong()
	{
		$.ajax({
			url: 'changeSong/',
			type: 'POST',
			data:{
				songIndex: currentSong
				},
			success: function(data){
				$("#jpId").jPlayer( "setFile", "/static/music/"+data['songName']); // for a local file
				$("#songName").html(data['songName']);
				$("#artistName").html(data['artistName']);
				$("#songTitle").html(data['songTitle']);
				$("#songUrl").attr('href',data['songUrl']);
				$("#jpId").jPlayer("load");
				$("#jpId").jPlayer("play");
			},
		});
	}
	
	$('#playButton').click(function(){
		$("#jpId").jPlayer("play");
	});
	
	
	$('#pauseButton').click(function(){
		$("#jpId").jPlayer("pause");
	});
	
	$('#stopButton').click(function(){
		$("#jpId").jPlayer("stop");
	});
	
	/****
	$('#volumeDown').click(function(){
		if (volume >= 10)
			volume = volume - 10;
			$("#jpId").jPlayer("volume", volume);
	});
	
	$('#volumeUp').click(function(){
		if (volume <= 90)
			volume = volume + 10;
			$("#jpId").jPlayer("volume", volume);
	});
	****/
	
	
	$('#rewindButton').click(function(){
		if (numSongs > 0){
			currentSong = (currentSong <= 1) ? numSongs : currentSong - 1;
			changeSong();
		}
		
	});
	
	function forwardSong(){
		if (numSongs > 0){
			currentSong = (currentSong >= numSongs) ? 1 : currentSong + 1;
			changeSong();
		}
	}
	
	$('#forwardButton').click(function(){
		forwardSong();
	});		
}



/****************************************************************************************
									NAVIGATION ANIMATIONS
****************************************************************************************/
wangle_js.prototype.enterNavigation = function (elem) {
	//self
	var self = this;
	var name=$(elem).attr('id').split('B')[0];
	self.navigationMenu_inside=true;
	$('#'+name+'Button').stop().animate({"bottom": "35px"}, 200);
	// if($('#navigationMenu').css('opacity')!='1'){
	// 	$('#navigationMenu').animate({"opacity": "1"}, 300);
	// }
};

wangle_js.prototype.leaveNavigation = function (elem) {
	//self
	var self = this;
	var name = $(elem).attr('id').split('B')[0];
	$('#'+name+'Button').stop().animate({"bottom": "15px"},200,function(){
		// if(self.navigationMenu_inside==false){
		// 	$('#navigationMenu').animate({"opacity": "0.35"}, 300);
		// }
	});
};

/****************************************************************************************
									MENU ANIMATIONS
****************************************************************************************/
wangle_js.prototype.enterMenu = function (elem) {
	var self = this;
	self.menu_inside=true;
	if ($(elem).attr('id') == 'connectMenu'){
		$('#connectMenu').stop().animate({"bottom": "-20px","opacity": "1"}, 300);
		$('#connectMenu').animate({"bottom": "-20px"},300);
		$('#connectHover').css('opacity','1');
	}else if ($(elem).attr('id') == 'musicMenu'){
		$('.musicInfo').fadeIn();
	}
	$(elem).stop().animate({"opacity": "1"}, 300);
};

wangle_js.prototype.leaveMenu = function (elem) {
	var self = this;
	self.menu_inside=false;
	if ($(elem).attr('id') == 'connectMenu'){
		$('#connectMenu').animate({"bottom": "-390px","opacity": "0.35","padding-top":"330px"}, 300);
		$('#connectHover').css('opacity','0.35');
	}else if ($(elem).attr('id') == 'musicMenu'){
		$('.musicInfo').fadeIn();
	}
	$(elem).animate({"opacity": "0.35"}, 300);
	$('#connectMenu').animate({"bottom": "-390px","padding-top":"330px"}, 300);
};

/****************************************************************************************
									LIVE EVENTS
****************************************************************************************/
wangle_js.prototype.liveEvents = function(){
	var self = this;

	$('#cancelButton, #contactCancel').live('click',function(){
		$('.overlay').hide();
		$('#velo').hide();
	});

	$('#loginButton').live('click',function(){
		$.ajax({
			url: '/login/',
			type: 'POST',
			data:{
				username: $('#loginUsername').val(),
				password: $('#loginPassword').val(),
			},
			success: function(data){
				$('#loginOverlay').html(data);
			},
			complete: function(data)
			{
				if ($('#authenticated').html()=='True'){
						$('.overlay').hide();
						$('#velo').hide();
						$('#clientLogged').html($('#bindLogMsg').html());
						window.location = "/";
				}
			}		
		});	
	});
};



/****************************************************************************************
									OBJECT
****************************************************************************************/
var wangle_object;


/****************************************************************************************
									ON READY
****************************************************************************************/
//this will only happen once because js scripts are only loaded once
$(document).ready(function(){
	wangle_object = new wangle_js();
});



/****************************************************************************************
									CLASS
****************************************************************************************/
var marketing_js = function () {
    this.init();
};



/****************************************************************************************
									INIT
****************************************************************************************/
//this only happens once in the life of the object
marketing_js.prototype.init = function () {
	this.mutex = false;
	this.liveEvents();
};



/****************************************************************************************
									START
****************************************************************************************/
//this happens everytime the html is fully loaded and is ready
//to receive events
marketing_js.prototype.start = function () {
	//self
	var self = this;
	$('#tab1,#marketingContent').show();
	$('#tabName1').css('font-weight','bold');
	$('#case1').removeClass('caseThumbnailTrans');
	
	self.setTransparencyContainer();
};




/****************************************************************************************
									LIVE EVENTS
****************************************************************************************/
marketing_js.prototype.liveEvents = function(){
	var self=this;

	$('.tabName').live('click', function(){
		var tabNum = $(this).attr('tabNumber');
		$('.tabName').css('font-weight','normal');
		$('#tabName'+tabNum).css('font-weight','bold');
		$('.tabs').hide();
		$('#tab'+tabNum).show();
		var height = parseInt($('#tabContentContainer'+tabNum).css('height'))  + 20;
		$('#tabTransparency'+tabNum).css('height',height);
	});
	
	$('.caseThumbnail').live('click', function(){
		var indexCase = $(this).attr('caseNumber');
		$('.caseThumbnail').addClass('caseThumbnailTrans');
		$(this).removeClass('caseThumbnailTrans');
		$.ajax({
			url: 'changeCase/',
			type: 'POST',
			data:{
				indexCase: indexCase
				},
			success: function(data){
				$('#marketingDisplay').html(data);
			},
			complete: function(){
				$('#tab1').show();
				self.setTransparencyContainer();
				$('#tabName1').css('font-weight','bold');
			},
		});
	
	});
};


/****************************************************************************************
									SET TRANSPARENCY CONTAINER
****************************************************************************************/
marketing_js.prototype.setTransparencyContainer = function () {
	var height = parseInt($('#tabContentContainer1').css('height'))  + 20;
	$('#tabTransparency1').css('height',height);
};



/****************************************************************************************
									LISTENERS
****************************************************************************************/
//Everytime we need to reload the listeners
marketing_js.prototype.listeners = function () {
	//self
	var self = this;
	

};
	

	

/****************************************************************************************
									OBJECT
****************************************************************************************/
var marketing_object;


/****************************************************************************************
									ON READY
****************************************************************************************/
//this will only happen once because js scripts are only loaded once
$(document).ready(function(){
	marketing_object = new marketing_js();
});



/****************************************************************************************
									CLASS
****************************************************************************************/
var photo_js = function () {
    this.init();
};



/****************************************************************************************
									INIT
****************************************************************************************/
//this only happens once in the life of the object
photo_js.prototype.init = function () {
	this.mutex = false;
	this.photoMenu_mutex=false;
	this.photoMenu_inside=false;
	this.liveEvents();
};



/****************************************************************************************
									SHOW FIRST IMAGE
****************************************************************************************/
//this happens everytime the html is fully loaded and is ready
//to receive events
photo_js.prototype.showFirstOnly = function () {
	$('#photoMenuBar,').show();
	$('#photoDisplay').attr('src',$('#photoOriginal1').attr('src'));
	photo_object.scaleImage('#photoOriginal1');
	
};


/****************************************************************************************
									START
****************************************************************************************/
//this happens everytime the html is fully loaded and is ready
//to receive events
photo_js.prototype.start = function () {
	//self
	var self = this;
	$('#photoMenuBar,#photoContent').show();
	$('#photoDisplay').attr('src',$('#photoOriginal1').attr('src'));
	photo_object.scaleImage('#photoOriginal1');
	$('#photoMenuBar').animate({"left": "0px"}, 400, function(){
		var t=setTimeout(self.leavePhotoMenu,3200);
	});
	$('#AllCategory').addClass('photoCategorySelected');
	
	 
	this.numPhotos = $('#photosLength').html();
	this.currentPhoto = 1;
	this.category = 'All';
	
	
	var img_loaded= false;
	var timer = new Array (this.numPhotos);
	var counter = new Array (this.numPhotos);
	var id = -1;
	
	function isImageOk() {
		// During the onload event, IE correctly identifies any images
		// that weren't downloaded as not complete. 
		var img = $('#photo'+id);
		counter[id] += 1;
		if (!img.complete){
			img_loaded = false;
			if (counter[id] > 5){
				clearInterval(timer[id]);
			}
		} else if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0){
			img_loaded = false;
			if (counter[id] > 5){
				clearInterval(timer[id]);
			}
		}
		else{
			// No other way of checking: assume it's ok.
			img_loaded = true;
			photo_object.scaleThumbnail('#photo'+id);
			alert("working" +id);
			clearInterval(timer[id]);
		}
	}
	
	for (var i=1;i<=this.numPhotos;i++){
		counter[i] = 0;
		id = i;
		timer[i]=setInterval(isImageOk,500);
	}
	
	//create the click and scroll menu
	$("#photos").clickNScroll({
		reverse: false,
		acceleration: .5,
	});
};


/****************************************************************************************
									SCALE IMAGE
****************************************************************************************/
photo_js.prototype.scaleImage = function (photoId){
		var prev_width = $(photoId).width();
		var prev_height = $(photoId).height();
		var aspect_ratio = prev_width / prev_height;
		var width = prev_width;
		var height = prev_height;
		if (aspect_ratio >= 1){
			if (prev_width > 1000){
				width = 1000;
				height = (1000 * prev_height) / prev_width;
			}
			if (height > 600){
				width = (600 * width) / height;
				height = 600;
			}			
		}else{
			if(width > 1000){
				width = (600 * prev_width) / prev_height;
				height = 600;
			}
			if (height > 600){
				width = (600 * width) / height;
				height = 600;
			}			
		}
		width = Math.round(width);
		height = Math.round(height);
		$('#photoDisplay').css('width',width);
		$('#photoDisplay').css('height',height);
}

photo_js.prototype.scaleThumbnail = function (photoId){
		var prev_width = $(photoId).width();
		var prev_height = $(photoId).height();
		var aspect_ratio = prev_width / prev_height;
		var width = prev_width;
		var height = prev_height;
		if (aspect_ratio >= 1){
			if (prev_width > 150){
				width = 150;
				height = (150 * prev_height) / prev_width;
			}
			if (height > 150){
				width = (150 * width) / height;
				height = 150;
			}			
		}else{
			if(width > 150){
				width = (150 * prev_width) / prev_height;
				height = 150;
			}
			if (height > 150){
				width = (150 * width) / height;
				height = 150;
			}	
		}
		width = Math.round(width);
		height = Math.round(height);
		var id = photoId.substring(6);
		//alert("photo"+id+": width-> "+width+", height-> "+height);
		$('#photo'+id).css('width',width);
		$('#photo'+id).css('height',height);
}


/****************************************************************************************
									LIVE EVENTS
****************************************************************************************/
photo_js.prototype.liveEvents = function(){
	document.onmousemove = (function() {
		var onmousestop = function() {
				//if the cursor stops and ths slideshow was playing
				$('#photoPlay').fadeOut('fast');
				document.getElementById('photoDisplay').onmousemove = function() {
				//if the cursor was stopped and start moving again
				$('#photoPlay').fadeIn('fast');
				//window.clearInterval(photoInterval);//the cursor moves and the slide show stops.
				}
		}, thread;
		return function() {
			clearTimeout(thread);
			thread = setTimeout(onmousestop, 1500);
		};
	})();
	
	 $('#photoPlay, #photoDisplay').live('click',function(){
		if ($('#photoPlay').attr('play')==0){
			//si play == 0 el slideshow estaba en pause
			$('#photoPlay').attr('play','1');
			$('#photoPlay').fadeOut("fast",function(){
				//cambiar de playImg a pauseImg y esconder el boton
				$('#photoPlay').attr('src','/static/img/AutoPauseButton.png');
			});
			//hideButton = window.setInterval("$('#photoPlay').attr('src','/static/img/AutoPauseButton.png')", 300);
			changeImage();
			photoInterval = window.setInterval(changeImage, 5000);
		}else{
			//si play == 1 el slideshow estaba en play
			$('#photoPlay').attr('src','/static/img/AutoPlayButton.png');
			$('#photoPlay').attr('play','0');
			window.clearInterval(photoInterval);
		}
	});
	
	function changeImage()
	{
		photo_object.currentPhoto = (photo_object.currentPhoto >= photo_object.numPhotos) ? 1 : photo_object.currentPhoto + 1;
		//if this photo is not of the selected category we skip it.
		while (($('#photo'+photo_object.currentPhoto).attr('category') != photo_object.category)&&(photo_object.category != 'All')){
			photo_object.currentPhoto = (photo_object.currentPhoto >= photo_object.numPhotos) ? 1 : photo_object.currentPhoto + 1;
		}
		$("#photoDisplay").fadeOut("slow", function(){
			$("#photoDisplay").attr('src', $('#photoOriginal'+photo_object.currentPhoto).attr('src'));
			photo_object.scaleImage('#photoOriginal'+photo_object.currentPhoto);
			$("#photoDisplay").fadeIn("slow");
		});
		
	}
	
	$('.photoCategory').live('click',function(){
		$('#'+photo_object.category+'Category').removeClass('photoCategorySelected');
		photo_object.category = $(this).html().trim();
		$('#'+photo_object.category+'Category').addClass('photoCategorySelected');
		var indexPhotoInCategory = 1;
		var first = true;
		for (var i=1;i<=photo_object.numPhotos;i++){
			var photo_cat = $('#photo'+i).attr('category').trim();
			if (photo_object.category == 'All'){
				$('#photoDiv'+i).show();
				if (first){
					indexPhotoInCategory = i;
					first = false;
				}
			}
			else if (photo_cat != photo_object.category)
				$('#photoDiv'+i).hide();
			else{
				if (first){
					indexPhotoInCategory = i;
					first = false;
				}
				$('#photoDiv'+i).show();
			}
			
		}
		$('#photoDisplay').attr('src',$('#photoOriginal'+indexPhotoInCategory).attr('src'));
		photo_object.scaleImage('#photoOriginal'+indexPhotoInCategory);
	 });
};

/****************************************************************************************
									LISTENERS
****************************************************************************************/
//Everytime we need to reload the listeners
photo_js.prototype.listeners = function () {
	//self
	var self = this;
	
	$('.photoInMenu').click(function(){
		if ($('#photoPlay').attr('play')==1){
			$('#photoPlay').trigger('click');
		}
		//multiply by 1 to convert from string to int
		photo_object.currentPhoto = $(this).attr('photoNum') * 1;
		var id = "#photoOriginal"+$(this).attr('photoNum');
		$('#photoDisplay').attr('src',$(id).attr('src'));
		photo_object.scaleImage(id);
	});
	
	//photo menu in the left, displays or hides depending on the cursor position
	$('#photoMenuBar').bind('mouseenter', function(event) {
		self.enterPhotoMenu();
	});

	$('#photoMenuBar').bind('mouseleave', function(event) {
		self.leavePhotoMenu();
	});
};
	

/****************************************************************************************
									NAVIGATION ANIMATIONS
****************************************************************************************/
photo_js.prototype.enterPhotoMenu = function () {
	//self
	var self = this;
	self.photoMenu_inside=true;
	if(!self.photoMenu_mutex){
		self.photoMenu_mutex=true;
		wangle_object.enterMenu();
		$('#photoMenuBar').animate({"left": "0px"}, 400,function(){
			self.photoMenu_mutex=false;
			if(self.photoMenu_inside==false){
				$('#photoMenuBar').trigger('mouseleave');
			}
		});
	}
};

photo_js.prototype.leavePhotoMenu = function () {
	self.photoMenu_inside=false;
	if(!self.photoMenu_mutex){
		self.photoMenu_mutex=true;
		wangle_object.leaveMenu();
		$('#photoMenuBar').animate({"left": "-280px"}, 400,function(){
			self.photoMenu_mutex=false;
			if(self.photoMenu_inside==true){
				$('#photoMenuBar').trigger('mouseenter');
			}
		});
	}
};

	
	

/****************************************************************************************
									OBJECT
****************************************************************************************/
var photo_object;


/****************************************************************************************
									ON READY
****************************************************************************************/
//this will only happen once because js scripts are only loaded once
$(document).ready(function(){
	photo_object = new photo_js();
});


/****************************************************************************************
									CLASS
****************************************************************************************/
var video_js = function () {
    this.init();
};


/****************************************************************************************
									INIT
****************************************************************************************/
//this only happens once in the life of the object
video_js.prototype.init = function () {
	/*Variables*/
	//flag to indicate that the object is working
	//like in the situation of clicking a button and waiting the response
	this.mutex = false;
	this.videoMenu_mutex=false;
	this.videoMenu_inside=false;
	//Initialization
	this.listeners();
	this.start();
	this.liveEvents();
};



/****************************************************************************************
									START
****************************************************************************************/
//this happens everytime the html is fully loaded and is ready
//to receive events
video_js.prototype.start = function () {
	//self
	var self = this;
	//$('#videoContent').show();
	
	changeVideo(1);
	$('video').get(0).load();
	
	
	$('#videoMenuBar').animate({"left": "0px"}, 400, function(){
		var t=setTimeout("$('#videoMenuBar').animate({'left': '-170px'}, 400)",3200);
	});
	
	$('#AllVideoCategory').addClass('videoCategorySelected');
	
	//create the click and scroll menu
	$("#videos").clickNScroll({
		reverse: false,
		acceleration: .5,
	});
	
	
};


/****************************************************************************************
									PAUSE VIDEO
****************************************************************************************/
//This method can be called from base-js to pause the video
video_js.prototype.pauseVideo = function () {
	$('video').get(0).pause();
}


/****************************************************************************************
									CHANGE VIDEO
****************************************************************************************/
function changeVideo(videoNumber){
	var videoMp4 = $('#video'+videoNumber).attr('vname_mp4');
	var videoOgg = $('#video'+videoNumber).attr('vname_ogg');
	//var videoWebm = $('#video'+videoNumber).attr('vname_webm');
	//var videoThumb = $('#video'+videoNumber).attr('src');
	if ($.browser.webkit){
		//Chrome is going to use mp4 for now, in the future it will be webM
		//$('#videoDisplay').attr('src',videoWebm);
		$('#videoDisplay').attr('src',videoMp4);
	}else if ($.browser.msie){
		$('#videoDisplay').attr('src',videoMp4);
	}else{
		$('#videoDisplay').attr('src',videoOgg);
	}
}


/****************************************************************************************
									LIVE EVENTS
****************************************************************************************/
video_js.prototype.liveEvents = function(){

	//video menu in the left, displays or hides depending on the cursor position

};


/****************************************************************************************
									NAVIGATION ANIMATIONS
****************************************************************************************/
video_js.prototype.enterVideoMenu = function () {
	//self
	var self = this;
	self.videoMenu_inside=true;
	if(!self.videoMenu_mutex){
		self.videoMenu_mutex=true;
		wangle_object.enterMenu();
		$('#videoMenuBar').animate({"left": "0px"}, 400,function(){
			self.videoMenu_mutex=false;
			if(self.videoMenu_inside==false){
				$('#videoMenuBar').trigger('mouseleave');
			}
		});
	}
};

video_js.prototype.leaveVideoMenu = function () {
	self.videoMenu_inside=false;
	if(!self.videoMenu_mutex){
		self.videoMenu_mutex=true;
		wangle_object.leaveMenu();
		$('#videoMenuBar').animate({"left": "-170px"}, 400,function(){
			self.videoMenu_mutex=false;
			if(self.videoMenu_inside==true){
				$('#videoMenuBar').trigger('mouseenter');
			}
		});
	}
};




/****************************************************************************************
									LISTENERS
****************************************************************************************/
//Everytime we need to reload the listeners
video_js.prototype.listeners = function () {
	//self
	var self = this;
	
	$('.videoInMenu').click(function(){
		$('video').get(0).pause();
		changeVideo($(this).attr('number'));
		$('video').get(0).load();
	});

	// var musicWasPlaying =  false;
	
	$('#videoPlay').click(function(){
		if ($('#videoPlay').attr('play')== 0){
			if ($("#jpId").jPlayer("getData", "diag.isPlaying")){
				fadeOutVolume();
				// musicWasPlaying = true;
			}
			$('video').get(0).play();
			$('video').get(0).controls = true;
			$('#videoPlay').fadeOut();
		}
	});
	
	
	
	function fadeOutVolume(){
		var volume = $("#jpId").jPlayer("getData", "volume");
		if(volume > 5){
			volume = volume - 5;
			$("#jpId").jPlayer("volume", volume);
			musicFade = window.setTimeout(fadeOutVolume, 150);
		}else{
			window.clearTimeout(musicFade);
			$("#jpId").jPlayer("pause");
			$("#jpId").jPlayer("volume",50);
		}
	}
	
	// function fadeInVolume(){
		// var volume = $("#jpId").jPlayer("getData", "volume");
		// if(volume <= 50){
			// volume = volume + 5;
			// $("#jpId").jPlayer("volume", volume);
			// musicFade = window.setTimeout(fadeInVolume, 150);
		// }else{
			// window.clearTimeout(musicFade);
			// $("#jpId").jPlayer("volume",50);
		// }
	// }
		
	// $('video').click(function() {	
		// if ($('video').get(0).paused == false){
			// $('video').get(0).pause();
			// $('video').get(0).controls = false;
			//// if (musicWasPlaying){
				//// $("#jpId").jPlayer("play");
				//// fadeInVolume();
			//// }
			// $('#videoPlay').fadeIn();
		// }
	// });
	document.getElementsByTagName("video")[0].addEventListener("pause", function() {
		$('video').get(0).controls = false;
		$('#videoPlay').fadeIn();
	}, true);
	
	
	//if the video is playing hide the playimage and show the controls
	if (!document.getElementsByTagName("video")[0].pause){
		$('video').get(0).controls = true;
		$('#videoPlay').fadeOut();
	}
	
	 
	var numVideos = $('#videosLength').html();
	var category = 'All';
	
	
	$('.videoCategory').live('click',function(){
		$('#'+category+'VideoCategory').removeClass('videoCategorySelected');
		category = $(this).html().trim();
		$('#'+category+'VideoCategory').addClass('videoCategorySelected');
		for (var i=1;i<=numVideos;i++){
			var video_cat = $('#video'+i).attr('category').trim();
			if (category == 'All')
				$('#video'+i).show();
			else if (video_cat != category)
				$('#video'+i).hide();
			else
				$('#video'+i).show();
			
		}
	 });
	 
	$('#videoMenuBar').bind('mouseenter', function(event) {
		self.enterVideoMenu();
	});

	$('#videoMenuBar').bind('mouseleave', function(event) {
		self.leaveVideoMenu();
	});
	
};


/****************************************************************************************
									OBJECT
****************************************************************************************/
var video_object;

/****************************************************************************************
									ON READY
****************************************************************************************/
//this will only happen once because js scripts are only loaded once
$(document).ready(function(){
	video_object = new video_js();
});

/* 
 * jQuery.clickNScroll v1.0
 *
 * Copyright (c) 2010 Joshua Faulkenberry
 * Dual licensed under the MIT and GPL licenses.
 * Joshua Faulkenberry
 *
 * $Date: 2010-10-25 18:55:27 -0700 (Mon, 25 Oct 2010) $
 * $Revision: 5 $
 */

(function($){ 
 
   jQuery.extend({
      mouse: {
         x: 0,
         y: 0
      },
      clickNScroll: {
         mousedown:false,
         emaX: 0,
         emaY: 0
      }  
   });
   
   jQuery.fn.extend({
      clickNScroll: function(options) {
         var ops = $.extend({
            allowHiliting:false,
            acceleration:.65,
            deceleration:.85,
            decelRate:64,
            reverse:false,
            rightMouse:false,
            allowThrowing:true,
            throwOnOut:true
         }, options || {});
         return this.each(function(){  
            var $this = $(this).data("options", ops);                                  
            if(!ops.allowHiliting) {
              if (jQuery.browser.msie) {
                 $this.get(0).onselectstart = function () { return false; };
              } 
              else {
                  $this.get(0).onmousedown = function(e){e.preventDefault()}
              }   
            }
            $this.mousedown(function(e) {
               $.clickNScroll.mousedown = $this;
            }).mouseup(function(e) {                                   
               if(ops.allowThrowing) sling($(this));  
               $.clickNScroll.mousedown = false;
            }).mouseout(function(e) { 
            	var from = e.relatedTarget || e.toElement;
                if (!from || from.nodeName == "HTML") {
	               if($.clickNScroll.mousedown && ops.allowThrowing && ops.throwOnOut)  sling($(this));   
	               $.clickNScroll.mousedown = false;
            	}
            })  
         });
      }      
   });
   
   function sling($this) {        
      var ops    = $this.data("options"),    
          changeX = ($.clickNScroll.emaX)*ops.deceleration,   
          changeY = ($.clickNScroll.emaY)*ops.deceleration;                                           
      if((changeX < .01 && changeX > -.01) || (changeY < .01 && changeY > -.01)) {return;}  
      move($this, changeX, changeY);            
      setTimeout(function() {
         sling($this);
      }, 1000/ops.decelRate);            
   }
   
   function move($this, changeX, changeY) {                                                                        
         if(($.clickNScroll.emaX < 0 && changeX > 0) || ($.clickNScroll.emaX > 0 && changeX < 0)) $.clickNScroll.emaX = 0;
         if(($.clickNScroll.emaY < 0 && changeY > 0) || ($.clickNScroll.emaY > 0 && changeY < 0)) $.clickNScroll.emaY = 0;
         
         var ops    = $this.data("options"),                                                                       
             amntX = ops.acceleration * changeX + (1 - ops.acceleration) * $.clickNScroll.emaX,
             amntY = ops.acceleration * changeY + (1 - ops.acceleration) * $.clickNScroll.emaY,
             scrollRight = $this[0].scrollWidth ? $this[0].scrollWidth - $this[0].clientWidth : $this[0].body.scrollWidth - $this[0].body.clientWidth,
             scrollBottom = $this[0].scrollHeight ? $this[0].scrollHeight - $this[0].clientHeight : $this[0].body.scrollHeight - $this[0].body.clientHeight; 

         if(($this.scrollLeft() <= 0 && changeX <= 0) ||  ($this.scrollLeft() >= scrollRight && changeX >= 0)) {}  
         else $this.scrollLeft($this.scrollLeft() + (amntX));
         if(($this.scrollTop() <= 0 && changeY <= 0) ||  ($this.scrollTop() >= scrollBottom && changeY >= 0)) {}  
         else $this.scrollTop($this.scrollTop() + (amntY));                                                       
         //$.clickNScroll.emaX = amntX;
         $.clickNScroll.emaY = amntY;
   }
   
   $(document).mousemove(function(e) {                                     
      if($.clickNScroll.mousedown) {      
         var $this  = $.clickNScroll.mousedown,
             ops    = $this.data("options");
         if(ops.rightMouse && e.button != 2) return;
         else if(!ops.rightMouse && e.button == 2) return;    
         var changeX = e.pageX - $.mouse.x;   
         var changeY = e.pageY - $.mouse.y; 
         if(!ops.reverse) {
          //changeX = 0-changeX;
          changeY = 0-changeY;
         }                                                                  
         move($this, changeX, changeY);
      }  
      $.mouse = {
         //x: e.pageX,
         y: e.pageY
      };                          
   }); 
   
})(jQuery);
/*
 * Modernizr v1.6
 * http://www.modernizr.com
 *
 * Developed by: 
 * - Faruk Ates  http://farukat.es/
 * - Paul Irish  http://paulirish.com/
 *
 * Copyright (c) 2009-2010
 * Dual-licensed under the BSD or MIT licenses.
 * http://www.modernizr.com/license/
 */
window.Modernizr=function(i,e,u){function s(a,b){return(""+a).indexOf(b)!==-1}function D(a,b){for(var c in a)if(j[a[c]]!==u&&(!b||b(a[c],E)))return true}function n(a,b){var c=a.charAt(0).toUpperCase()+a.substr(1);c=(a+" "+F.join(c+" ")+c).split(" ");return!!D(c,b)}function S(){f.input=function(a){for(var b=0,c=a.length;b<c;b++)L[a[b]]=!!(a[b]in h);return L}("autocomplete autofocus list placeholder max min multiple pattern required step".split(" "));f.inputtypes=function(a){for(var b=0,c,k=a.length;b<
k;b++){h.setAttribute("type",a[b]);if(c=h.type!=="text"){h.value=M;if(/^range$/.test(h.type)&&h.style.WebkitAppearance!==u){l.appendChild(h);c=e.defaultView;c=c.getComputedStyle&&c.getComputedStyle(h,null).WebkitAppearance!=="textfield"&&h.offsetHeight!==0;l.removeChild(h)}else/^(search|tel)$/.test(h.type)||(c=/^(url|email)$/.test(h.type)?h.checkValidity&&h.checkValidity()===false:h.value!=M)}N[a[b]]=!!c}return N}("search tel url email datetime date month week time datetime-local number range color".split(" "))}
var f={},l=e.documentElement,E=e.createElement("modernizr"),j=E.style,h=e.createElement("input"),M=":)",O=Object.prototype.toString,q=" -webkit- -moz- -o- -ms- -khtml- ".split(" "),F="Webkit Moz O ms Khtml".split(" "),v={svg:"http://www.w3.org/2000/svg"},d={},N={},L={},P=[],w,Q=function(a){var b=document.createElement("style"),c=e.createElement("div");b.textContent=a+"{#modernizr{height:3px}}";(e.head||e.getElementsByTagName("head")[0]).appendChild(b);c.id="modernizr";l.appendChild(c);a=c.offsetHeight===
3;b.parentNode.removeChild(b);c.parentNode.removeChild(c);return!!a},o=function(){var a={select:"input",change:"input",submit:"form",reset:"form",error:"img",load:"img",abort:"img"};return function(b,c){c=c||document.createElement(a[b]||"div");b="on"+b;var k=b in c;if(!k){c.setAttribute||(c=document.createElement("div"));if(c.setAttribute&&c.removeAttribute){c.setAttribute(b,"");k=typeof c[b]=="function";if(typeof c[b]!="undefined")c[b]=u;c.removeAttribute(b)}}return k}}(),G={}.hasOwnProperty,R;R=
typeof G!=="undefined"&&typeof G.call!=="undefined"?function(a,b){return G.call(a,b)}:function(a,b){return b in a&&typeof a.constructor.prototype[b]==="undefined"};d.flexbox=function(){var a=e.createElement("div"),b=e.createElement("div");(function(k,g,r,x){g+=":";k.style.cssText=(g+q.join(r+";"+g)).slice(0,-g.length)+(x||"")})(a,"display","box","width:42px;padding:0;");b.style.cssText=q.join("box-flex:1;")+"width:10px;";a.appendChild(b);l.appendChild(a);var c=b.offsetWidth===42;a.removeChild(b);
l.removeChild(a);return c};d.canvas=function(){var a=e.createElement("canvas");return!!(a.getContext&&a.getContext("2d"))};d.canvastext=function(){return!!(f.canvas&&typeof e.createElement("canvas").getContext("2d").fillText=="function")};d.webgl=function(){var a=e.createElement("canvas");try{if(a.getContext("webgl"))return true}catch(b){}try{if(a.getContext("experimental-webgl"))return true}catch(c){}return false};d.touch=function(){return"ontouchstart"in i||Q("@media ("+q.join("touch-enabled),(")+
"modernizr)")};d.geolocation=function(){return!!navigator.geolocation};d.postmessage=function(){return!!i.postMessage};d.websqldatabase=function(){return!!i.openDatabase};d.indexedDB=function(){for(var a=-1,b=F.length;++a<b;){var c=F[a].toLowerCase();if(i[c+"_indexedDB"]||i[c+"IndexedDB"])return true}return false};d.hashchange=function(){return o("hashchange",i)&&(document.documentMode===u||document.documentMode>7)};d.history=function(){return!!(i.history&&history.pushState)};d.draganddrop=function(){return o("drag")&&
o("dragstart")&&o("dragenter")&&o("dragover")&&o("dragleave")&&o("dragend")&&o("drop")};d.websockets=function(){return"WebSocket"in i};d.rgba=function(){j.cssText="background-color:rgba(150,255,150,.5)";return s(j.backgroundColor,"rgba")};d.hsla=function(){j.cssText="background-color:hsla(120,40%,100%,.5)";return s(j.backgroundColor,"rgba")||s(j.backgroundColor,"hsla")};d.multiplebgs=function(){j.cssText="background:url(//:),url(//:),red url(//:)";return/(url\s*\(.*?){3}/.test(j.background)};d.backgroundsize=
function(){return n("backgroundSize")};d.borderimage=function(){return n("borderImage")};d.borderradius=function(){return n("borderRadius","",function(a){return s(a,"orderRadius")})};d.boxshadow=function(){return n("boxShadow")};d.textshadow=function(){return e.createElement("div").style.textShadow===""};d.opacity=function(){var a=q.join("opacity:.5;")+"";j.cssText=a;return s(j.opacity,"0.5")};d.cssanimations=function(){return n("animationName")};d.csscolumns=function(){return n("columnCount")};d.cssgradients=
function(){var a=("background-image:"+q.join("gradient(linear,left top,right bottom,from(#9f9),to(white));background-image:")+q.join("linear-gradient(left top,#9f9, white);background-image:")).slice(0,-17);j.cssText=a;return s(j.backgroundImage,"gradient")};d.cssreflections=function(){return n("boxReflect")};d.csstransforms=function(){return!!D(["transformProperty","WebkitTransform","MozTransform","OTransform","msTransform"])};d.csstransforms3d=function(){var a=!!D(["perspectiveProperty","WebkitPerspective",
"MozPerspective","OPerspective","msPerspective"]);if(a)a=Q("@media ("+q.join("transform-3d),(")+"modernizr)");return a};d.csstransitions=function(){return n("transitionProperty")};d.fontface=function(){var a,b=e.head||e.getElementsByTagName("head")[0]||l,c=e.createElement("style"),k=e.implementation||{hasFeature:function(){return false}};c.type="text/css";b.insertBefore(c,b.firstChild);a=c.sheet||c.styleSheet;b=k.hasFeature("CSS2","")?function(g){if(!(a&&g))return false;var r=false;try{a.insertRule(g,
0);r=!/unknown/i.test(a.cssRules[0].cssText);a.deleteRule(a.cssRules.length-1)}catch(x){}return r}:function(g){if(!(a&&g))return false;a.cssText=g;return a.cssText.length!==0&&!/unknown/i.test(a.cssText)&&a.cssText.replace(/\r+|\n+/g,"").indexOf(g.split(" ")[0])===0};f._fontfaceready=function(g){g(f.fontface)};return b('@font-face { font-family: "font"; src: "font.ttf"; }')};d.video=function(){var a=e.createElement("video"),b=!!a.canPlayType;if(b){b=new Boolean(b);b.ogg=a.canPlayType('video/ogg; codecs="theora"');
b.h264=a.canPlayType('video/mp4; codecs="avc1.42E01E"')||a.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');b.webm=a.canPlayType('video/webm; codecs="vp8, vorbis"')}return b};d.audio=function(){var a=e.createElement("audio"),b=!!a.canPlayType;if(b){b=new Boolean(b);b.ogg=a.canPlayType('audio/ogg; codecs="vorbis"');b.mp3=a.canPlayType("audio/mpeg;");b.wav=a.canPlayType('audio/wav; codecs="1"');b.m4a=a.canPlayType("audio/x-m4a;")||a.canPlayType("audio/aac;")}return b};d.localstorage=function(){try{return"localStorage"in
i&&i.localStorage!==null}catch(a){return false}};d.sessionstorage=function(){try{return"sessionStorage"in i&&i.sessionStorage!==null}catch(a){return false}};d.webWorkers=function(){return!!i.Worker};d.applicationcache=function(){return!!i.applicationCache};d.svg=function(){return!!e.createElementNS&&!!e.createElementNS(v.svg,"svg").createSVGRect};d.inlinesvg=function(){var a=document.createElement("div");a.innerHTML="<svg/>";return(a.firstChild&&a.firstChild.namespaceURI)==v.svg};d.smil=function(){return!!e.createElementNS&&
/SVG/.test(O.call(e.createElementNS(v.svg,"animate")))};d.svgclippaths=function(){return!!e.createElementNS&&/SVG/.test(O.call(e.createElementNS(v.svg,"clipPath")))};for(var H in d)if(R(d,H)){w=H.toLowerCase();f[w]=d[H]();P.push((f[w]?"":"no-")+w)}f.input||S();f.crosswindowmessaging=f.postmessage;f.historymanagement=f.history;f.addTest=function(a,b){a=a.toLowerCase();if(!f[a]){b=!!b();l.className+=" "+(b?"":"no-")+a;f[a]=b;return f}};j.cssText="";E=h=null;i.attachEvent&&function(){var a=e.createElement("div");
a.innerHTML="<elem></elem>";return a.childNodes.length!==1}()&&function(a,b){function c(p){for(var m=-1;++m<r;)p.createElement(g[m])}function k(p,m){for(var I=p.length,t=-1,y,J=[];++t<I;){y=p[t];m=y.media||m;J.push(k(y.imports,m));J.push(y.cssText)}return J.join("")}var g="abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video".split("|"),r=g.length,x=RegExp("<(/*)(abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video)",
"gi"),T=RegExp("\\b(abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video)\\b(?!.*[;}])","gi"),z=b.createDocumentFragment(),A=b.documentElement,K=A.firstChild,B=b.createElement("style"),C=b.createElement("body");B.media="all";c(b);c(z);a.attachEvent("onbeforeprint",function(){for(var p=-1;++p<r;)for(var m=b.getElementsByTagName(g[p]),I=m.length,t=-1;++t<I;)if(m[t].className.indexOf("iepp_")<0)m[t].className+=" iepp_"+
g[p];K.insertBefore(B,K.firstChild);B.styleSheet.cssText=k(b.styleSheets,"all").replace(T,".iepp_$1");z.appendChild(b.body);A.appendChild(C);C.innerHTML=z.firstChild.innerHTML.replace(x,"<$1bdo")});a.attachEvent("onafterprint",function(){C.innerHTML="";A.removeChild(C);K.removeChild(B);A.appendChild(z.firstChild)})}(this,document);f._enableHTML5=true;f._version="1.6";l.className=l.className.replace(/\bno-js\b/,"")+" js";l.className+=" "+P.join(" ");return f}(this,this.document);

