/* определение браузеров */

var l2 = null; 
var t;
//var hideTime = 200;
var opera=gecko=ie=false;
var browser=navigator.userAgent.toLowerCase();
var version = parseFloat(navigator.appVersion);
if(browser.match('opera'))opera=true;
if(browser.match('gecko'))gecko=true;
if(browser.match('msie'))
{
  if(!opera)ie=true;
  if(browser.match('msie 6'))version=6;
  else if(browser.match('msie 7'))version=7;
}

function png(element)
/*
   корректное отображение png-картинок в ie
   вызывается в стилях
   для img задаём class='png'
   для элементов с png-фоном задаём class='scale' (фон тянется (повторяется)) или class='crop' (фон не повторяется)
*/
{if(ie){
try{
var src,method='scale';
var classname=element.className;
if(classname.match('png'))
{
  src=element.getAttribute('src');
  element.setAttribute('src','img/1.gif');
}
else if(classname.match('scale')||classname.match('crop'))
{
  src=element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/img)[1];
  element.style.backgroundImage='none';
  if(classname.match('crop'))method='crop';
}
element.style.filter="progid:dximagetransform.microsoft.alphaimageloader(src='"+src+"',sizingmethod="+method+")";
}
catch(e){}
}}

function show(obj) {
if (document.getElementById(obj).style.display == 'none')
document.getElementById(obj).style.display = 'block';
else document.getElementById(obj).style.display = 'none';
}
	  			
function popupWindow(url, w, h) {
	href = url;
	sh = screen.height - 80;
	if (document.all) sh -= 40;
	sw = screen.width;
	if (h > sh) h = sh;
	if (w > sw) w = sw;
	posX = sw/2 - w/2;
	posY = sh/2 - h/2;
	if (posY < 0) posY = 0;
	if (posX < 0) posX = 0;
	posCode = (document.all) ? ",left=" + posX + ",top=" + posY : ",screenX=" + posX + ",screenY=" + posY;
	moreWin = window.open (href, "popup", "status=no, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, width=" + w + ", height=" + h + posCode);
	moreWin.focus();
}

function showHelp(text){
	alert(text);
}

function HideL2 () {
	if (l2) {
		var e2 = document.getElementById(l2);
		e2.style.visibility = "hidden";
	}
}

function ShowHelp(id) {
	if (t) clearTimeout(t);
	if (l2 != id) {
		HideL2();
	}
	var e = document.getElementById(id);
	if (!e) return;
	l2 = id;
	e.style.visibility = "visible";
}

function HideHelp(hideTime) {
	if (t) clearTimeout(t);
	t = setTimeout(HideL2, hideTime);
}

(function($) {
$(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;
	}
	function eraseCookie(name) {
		createCookie(name,"",-1);
	}

	$('ul.tabs').each(function(i) {
		var cookie = readCookie('tabCookie'+i);
		if (cookie) $(this).find('li').eq(cookie).addClass('current').siblings().removeClass('current')
			.parents('div.section').find('div.box').hide().eq(cookie).show();
	})

	$('ul.tabs').delegate('li:not(.current)', 'click', function() {
		$(this).addClass('current').siblings().removeClass('current')
			.parents('div.section').find('div.box').hide().eq($(this).index()).show();
		var ulIndex = $('ul.tabs').index($(this).parents('ul.tabs'));
		eraseCookie('tabCookie'+ulIndex);
		createCookie('tabCookie'+ulIndex, $(this).index(), 365);
	})

})
})(jQuery)
