$(document).ready(function() {
	// Флэш
	ShowFlash(cookieval('UseFlash', document.cookie));
	$('.flash-switcher').click(function() { 
		var useFlash = cookieval('UseFlash', document.cookie);
		var expDate = new Date();
		expDate.setDate(expDate.getDate() + 365);
		document.cookie = 'UseFlash = ' + !useFlash + '; path=/; expires=' + expDate.toGMTString(); 
		ShowFlash(!useFlash);
		return false;
	});	
});

function ShowFlash(useFlash) {
	if (useFlash)	{ 
		$('.mainflash').flashembed(
			{ src: '/_common/flash/flag.swf', width: '613', height: '73', wmode: 'transparent' },
			{ version: [10] }
		);
		$('.flash-man').flashembed(
			{ src: '/_common/flash/man.swf', width: '145', height: '240', wmode: 'transparent' },
			{ version: [8] }
		);		
		$('.content-block').css('background-image', 'none');
		$('.flash-switcher').text('выключить флеш');
	}
	else {
		$('.mainflash').html('');
		$('.flash-man').html('');
		$('.content-block').css('background-image', "url('/images/template/content-block-bg.jpg')");
		$('.flash-switcher').text('включить флеш');
	}
}

function cookieval(cookiename, cookiestring) {
	var startloc = cookiestring.indexOf(cookiename);
	if (startloc == -1) return true;
	var seploc = cookiestring.indexOf('=', startloc);
	var endloc = cookiestring.indexOf(';', startloc);
	if (endloc == -1) endloc = cookiestring.length;
	if ((cookiestring.substring(seploc + 1, endloc)) == 'true') return true;
	return false;
}
