{% autoescape None %}
<!doctype html>
<html>
	<head>
	    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
		<meta name="apple-mobile-web-app-capable" content="yes">

		{% for url in fireEvent('clientscript.get_styles', as_html = True, location = 'front', single = True) %}
		<link rel="stylesheet" href="{{ Env.get('web_base') }}{{ url }}" type="text/css">{% end %}
		{% for url in fireEvent('clientscript.get_scripts', as_html = True, location = 'front', single = True) %}
		<script type="text/javascript" src="{{ Env.get('web_base') }}{{ url }}"></script>{% end %}

		{% for url in fireEvent('clientscript.get_scripts', as_html = True, location = 'head', single = True) %}
		<script type="text/javascript" src="{{ Env.get('web_base') }}{{ url }}"></script>{% end %}
		{% for url in fireEvent('clientscript.get_styles', as_html = True, location = 'head', single = True) %}
		<link rel="stylesheet" href="{{ Env.get('web_base') }}{{ url }}" type="text/css">{% end %}

		<link href="{{ Env.get('static_path') }}images/favicon.ico" rel="icon" type="image/x-icon" />
		<link rel="apple-touch-icon" href="{{ Env.get('static_path') }}images/homescreen.png" />

		<script type="text/javascript" src="https://www.youtube.com/player_api" defer="defer"></script>

		<script type="text/javascript">

            window.addEvent('load', function(){

                if(window.getSize().x <= 480)
                    setTimeout(function(){
                        window.scrollTo(0, 1);
                        window.scrollTo(0, 0);
                    }, 100);

            });

			window.addEvent('domready', function() {

				new Uniform();

				Api.setup({
					'url': {{ json_encode(Env.get('api_base')) }},
					'path_sep': {{ json_encode(sep) }},
					'is_remote': false
				});

				$(document.body).set('data-api', window.location.protocol + '//' + window.location.host + Api.createUrl().replace('/default/', '/'));

				// Catch errors
				window.onerror = function(message, file, line){

					p(message, file, line);

					Api.request('logging.log', {
						'data': {
							'type': 'error',
							'message': Browser.name + ' ' + Browser.version + ': \n' + message,
							'page': window.location.href.replace(window.location.host, 'HOST'),
							'file': file.replace(window.location.host, 'HOST'),
							'line': line
						}
					});

					return true;
				}

				Quality.setup({
					'profiles': {{ json_encode(fireEvent('profile.all', single = True)) }},
					'qualities': {{ json_encode(fireEvent('quality.all', single = True)) }}
				});

				Status.setup({{ json_encode(fireEvent('status.all', single = True)) }});

				File.Type.setup({{ json_encode(fireEvent('file.types', single = True)) }});

				CategoryList.setup({{ json_encode(fireEvent('category.all', single = True)) }});

				App.setup({
					'base_url': {{ json_encode(Env.get('web_base')) }},
					'args': {{ json_encode(Env.get('args')) }},
					'options': {{ json_encode(('%s' % Env.get('options'))) }},
					'app_dir': {{ json_encode(Env.get('app_dir')) }},
					'data_dir': {{ json_encode(Env.get('data_dir')) }},
					'pid': {{ json_encode(Env.getPid()) }},
					'userscript_version': {{ json_encode(fireEvent('userscript.get_version', single = True)) }}
				});
			})

			{% if Env.setting('show_wizard') %}
				if(!window.location.href.contains('wizard'))
					window.location = '{{ Env.get('web_base') }}wizard/'
			{% end %}

		</script>
		<title>CouchPotato</title>
	</head>
	<body></body>
</html>