function get_user_format(){
	var height=0;
	var width=0;
	if (self.screen) {     // для Netscape и IE версий 4 и выше
		width = screen.width
		height = screen.height
	}else if (self.java) {   // для Netscape3
		var jkit = java.awt.Toolkit.getDefaultToolkit();
		var scrsize = jkit.getScreenSize();       
		width = scrsize.width; 
		height = scrsize.height; 
	}
	var format = detect_format();
	if(width > 0 && height > 0 && format != 0){  
		document.writeln('<li>Ваше разрешение: ');
		document.writeln('<a href="/format/'+format.ratio+'/'+format.resivl+'/"><b>',width,'x',height,'</b> pix</a>');
		document.writeln('</li>');
	}else{
		document.writeln('<li>Разрешение вашего монитора не определено!</li>');
	}
}

function get_user_resolution(image_base_url, image_suff){
	var format = detect_format();
	if(format != 0){
		document.write('<a href="' + image_base_url + format.w + '-' + format.h + image_suff + '" target="_blank">' + format.w + 'x' + format.h + '</a>');
	}else{
		document.write('Не определено');
	}
	return 0;
}

function get_formats(){
	var formats = {
		'4:3':[
			{r:1,w:1024,h:768},
			{r:2,w:1152,h:864},
			{r:3,w:1280,h:960},
			{r:4,w:1400,h:1050},
			{r:5,w:1600,h:1200},
			{r:6,w:1920,h:1440},
			{r:7,w:2048,h:1536},
			{r:8,w:3200,h:2400},
			{r:9,w:6400,h:4800}
		],'5:4':[
			{r:10,w:1280,h:1024},
			{r:11,w:2560,h:2048},
			{r:12,w:5120,h:4096}
		],'16:9':[
			{r:13,w:1280,h:720},
			{r:14,w:1366,h:768},
			{r:15,w:1920,h:1080},
			{r:16,w:2048,h:1152}
		],'16:10':[
			{r:17,w:1280,h:800},
			{r:18,w:1440,h:900},
			{r:19,w:1680,h:1050},
			{r:20,w:1920,h:1200},
			{r:21,w:2560,h:1600},
			{r:22,w:3840,h:2400},
			{r:23,w:7680,h:4800}
		],'25:16':[
			{r:24,w:1200,h:800},
			{r:25,w:1500,h:1000},
			{r:26,w:1600,h:1024},
			{r:27,w:2300,h:1530},
			{r:28,w:3200,h:2048},
			{r:29,w:6400,h:4096}
		]
	}
	return formats;
}

function detect_format(){
	var w = screen.width, h = screen.height;
	var formats = get_formats();
	for(var res in formats){
		var sub_formats = formats[res];
		var ara = res.split(':');
		for(var fmt in sub_formats){
			f = sub_formats[fmt];
			if(w == f.w && h == f.h){
				f.f = fmt;
				f.ratio = ara[0] + '-' + ara[1];
				f.resivl = f.w + '-' + f.h;
				return f;
			}
		}
	}
	return 0;
}

function get_pictuire_id(){
	var m, id = 0;
	if(m = location.href.match(/wallpapers\/[^\/]*\/(\d+)\//)) {
		return m[1];
	}
	if(m = location.href.match(/wallpapers\/[^\/]*\/[^\/]*\/(\d+)\//)) {
		return m[1];
	}
	return id;
}

function render_link(res, title, basecat){
	return '<li><a target="_blank" href="/wallpapers/'+basecat+'/'+get_pictuire_id()+'/' + res + '.html">' + title +'</a></li>';
}

function clear_timeuout(obj){
	if(obj.to_h){
		clearTimeout(obj.to_h);
	}
	obj.to_h = 0;
}

function set_timeuout(obj, timer){
	obj.to_h = setTimeout(function(){
		$(obj).hide();
	}, timer);
}

function render_resolutions(basecat){
	var formats = get_formats();
	var id = get_pictuire_id();
	var fmt = detect_format();
	if(fmt != 0){
		for(var i in available_formats){
			var _fmt = available_formats[i];
			if(_fmt.w == fmt.w && _fmt.h == fmt.h){
				document.writeln('<li id="resol_name">Ваше разрешение:</li>');
				document.writeln(render_link(''+fmt.w+'-'+fmt.h, '' + fmt.w + 'x' + fmt.h, basecat));
				break;
			}
		}
	}
	$(document).ready(function(){
		$('#resolution_menu').mouseover(function(){
			clear_timeuout(this)
		});
		$('#resolution_menu').mouseout(function(){
			set_timeuout(this, 1000)
		});
	});
	return;
	for(var res in formats){
		var sub_formats = formats[res];
		document.writeln('<li id="resol_name">'+res+'</li>');
		for(var i in sub_formats){
			fmt = sub_formats[i];
			document.writeln(render_link(''+fmt.w+'-'+fmt.h, '' + fmt.w + 'x' + fmt.h, basecat));
		}
	}
}

