window.onorientationchange = function() {
  var orientation = window.orientation;
  
  if(orientation==0) {
  	$('#main').removeClass('portrait');
  	$('#main').addClass('landscape');
  } else {
  	$('#main').removeClass('portrait');
  	$('#main').addClass('landscape');
  }
 
}
 
  
$(document).ready(function() {
	jQuery.extend( jQuery.easing,
	{
		def: 'easeOutQuint',
		easeOutQuint: function (x, t, b, c, d) {
			return c*((t=t/d-1)*t*t*t*t + 1) + b;
		}
	});

	$('#legal_info').hide();
	$('#menu ul').hide();
	$('#menu ul.active').show();
	   
	$('#menu li a').click(function(e) {
		var checkElement = $(this).next();
	
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			return true;
		}
	      
	    if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
	    	e.preventDefault();
	    	$('#menu li a').removeClass('current');
	    	$(this).addClass('current');
	    	var href = $(this).attr('href');
	    	
	    	if(!$('#menu ul:visible').length) {
				return window.location.href = href;
	    	}
	    	
			$('#menu ul:visible').slideUp('normal', function() {
				checkElement.slideDown('normal', function() {
					return setTimeout("window.location.href = '" + href + "'", 500);
				});
			});
			
		}
	});
	
	$('#show_legal_link').mouseenter(function() {
		$('#legal_info').slideToggle();
	});
	
	$('#show_legal_link').mouseleave(function() {
		$('#legal_info').slideToggle();
	});
	
	if($('.gallery_img').length) {
		$('.gallery_img').each(function(){
        	$('<img/>')[0].src = $(this).attr('href');
    	});
	
	
		$('.gallery_img').click(function(e) {
			if($(this).hasClass('active')) {
				return false;
			}
		
			//e.preventDefault();
			$('.gallery_img').removeClass('active');
			$(this).addClass('active');
			$('#main_image').hide();
			$('#main_image').attr('src', $(this).attr('href')).delay(100).fadeIn('slow');
			return false;
		});
	}
	

	$('.content_toggle').click(function() {
		var subcontent = $('.subcontent_div');
		
		if(!subcontent.hasClass('closed')) {
			subcontent.addClass('closed');
			subcontent.animate({left: '-411px'}, 800);
		} else {
			subcontent.removeClass('closed');
			subcontent.animate({left: '0px'}, 800);
		}
	});
	
	
	$('#content').css('width', $(window).width()-220);
	
	
	var deviceAgent = navigator.userAgent.toLowerCase();
	var agentID = deviceAgent.match(/(iphone|ipod)/);
	
	$(window).resize(function() {
		//if (agentID) {
			var w = $(window).width();
			$('#content').css('width', w-220);
		//}
	});
	
	setTimeout(function () { window.scrollTo(0, 1); }, 1000);

});
