(function(){
	
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

var cookie = Boolean(readCookie('mobile'));
var $ = jQuery;
var mobile = screen.width <= 699;
var agent = navigator.userAgent.toLowerCase();

//mobile = mobile || agent.search('android') !== -1;
mobile = mobile || agent.search('ipad') !== -1;
mobile = mobile || agent.search('iphone') !== -1;
mobile = mobile || agent.search('ipod') !== -1;

function disable(){
	createCookie('mobile', 'true', 1);
	window.location.reload();
}

function show() {
	var body = $('body');
	var head = $('head');
	var viewport = $('<meta/>');
	var fly      = $('#mobile-fly');
	var loading  = $('#mobile-fly-loading');
	var removes  = $('.remove');
	var closer   = $('#closer');
	
	body.children().hide();
	fly.appendTo(body).show();
	loading.appendTo(body).show()
		.animate({opacity:0}, 1000)
		.animate({zIndex: 999}, 0);
	viewport
		.attr('name', 'viewport')
		.attr('content', 'width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;')
		.prependTo(head);
	closer.click(disable);
	removes.remove();
}

if (mobile && !cookie) $(show);

})();
