var deviceOrientation = "";
$(document).ready(function() {
	$('#site-switcher').hide();
	
	setTimeout("SwitcherSlideDown()",1000);
	
	init_orientation();
});


function autoFontSize() {
	var contentWidth = $(window).width();

	if($('#site-switcher').hasClass('site-switcher-device-iphone')) {
		var deviceWidth = 320;
	} else if($('#site-switcher').hasClass('site-switcher-device-ipad')) {
		var deviceWidth = 768;
	}	

	if(deviceOrientation == "left" || deviceOrientation == "right") {
		if($('#site-switcher').hasClass('site-switcher-device-iphone')) {
			deviceWidth = 480;
		} else if($('#site-switcher').hasClass('site-switcher-device-ipad')) {
			deviceWidth = 1024;
		}
	}

	var maxWidth = $('#site-switcher a').width();
	
	var newSize = Math.round((18 * contentWidth) / deviceWidth);

	$('#site-switcher a').css('font-size', newSize);
}



function SwitcherSlideDown() {
	$('#site-switcher').slideDown();
}


function init_orientation() {
	$(window).bind('orientationchange', function() {
		updateOrientation();
	});
	
	updateOrientation();
}

function updateOrientation(){

	var contentType = "";
	switch(window.orientation){
		case 0:
		contentType += "normal";
		break;

		case -90:
		contentType += "right";
		break;

		case 90:
		contentType += "left";
		break;

		case 180:
		contentType += "flipped";
		break;
	}
	
	deviceOrientation = contentType;
	
	$('#site-switcher').removeClass('normal');
	$('#site-switcher').removeClass('right');
	$('#site-switcher').removeClass('left');
	$('#site-switcher').removeClass('flipped');
	
	if(deviceOrientation != "") {
		$('#site-switcher').addClass(deviceOrientation);
	}
	
	autoFontSize();
	$('#site-switcher').width($(document).width());
}


