$(document).ready(function(){
	var total    = 3;
	var interval = 10000;
	var speed    = 2000;

	var html     = '';
	for (var i = 1; i <= total; i++) {
		html += '<img id="ill' + i + '" src="/design/illustration/' + i + '.jpg" alt="" style="display:none">';
	}
	$('#illustrations').html(html);
	$('#illustrations img:first-child').show();
	
	var curr = 0;
	fade = function (delay) {
		setTimeout(function(){
			$('#ill' + (curr + 1)).fadeOut(speed);
			curr = (curr + 1) % total;
			$('#ill' + (curr + 1)).fadeIn(speed);
			fade(delay);
		}, delay);
	}

	fade(interval);
});

function showPopup (menuId) {
	var menu = document.getElementById(menuId);
	if (menu) menu.style.display = 'block';
}

function hidePopup (menuId) {
	var menu = document.getElementById(menuId);
	if (menu) menu.style.display = 'none';
}

function ChangeImg() {
	if(document.images) {
		eval("document."+ChangeImg.arguments[0]+".src=('"+ChangeImg.arguments[1]+"')");
	}
}

function preload() {
	if (document.images) { 
		var imgsrc = preload.arguments;
		arr=new Array(imgsrc.length);
		for (var j=0; j<imgsrc.length; j++) {
			arr[j] = new Image; arr[j].src = imgsrc[j]; 
		}
	}
}

function popup (linkObj,w_w,w_h,ext) {
	var ext = ext || 0;		
  window.open(linkObj.href,linkObj.target,'width='+w_w+',height='+w_h+
    ',resizable='+ext+',scrollbars='+ext+',location=0,toolbar=0,menubar=0,status=0');
  return false;
}

function imgOpen(imgLink,Title,width,height) {
	var doResize;
	if (width == null) {width = 100;height = 100;doResize=1}
  if (typeof(window.resizeBy)=='undefined') return true;
  imgWndw=window.open('',imgLink.target,'width='+width+',height='+height+
    ',toolbar=no,menubar=no,location=no,status=no,'+
    'resizable=yes,scrollbars=no,left='+(screen.width>>>2)+
    ',top='+(screen.height>>>4));
  if (doResize) self.focus();
  var imgTitle=(Title)?Title:imgLink.href;
  with (imgWndw.document){
    open();
    write('<ht'+'ml><he'+'ad><ti'+'tle>'+imgTitle+'</ti'+'tle>'+
    '</he'+'ad><bo'+'dy leftmargin="0" topmargin="0" '+
    'rightmargin="0" bottommargin="0" marginwidth="0" '+
    'style="margin:0;padding:0;position:fixed;overflow:none;" '+
    'marginheight="0"><img src="'+imgLink.href+'" border="0" '+
    ' alt="'+imgTitle+'" title="'+imgTitle+'"/></bo'+
    'dy></ht'+'ml>');
    close();
  }
  if (doResize==1) {resId=setInterval('imgResize()',100);}
  return false;
}

function imgResize() {
  var w=imgWndw.document.images[0].width;
  if (w>screen.availWidth) w=screen.availWidth;
  var h=imgWndw.document.images[0].height;
  if (h>screen.availHeight) h=screen.availHeight;
  if (w>50 && h>50) {
    var ww=(imgWndw.innerWidth)?imgWndw.innerWidth:((document.body)?
      imgWndw.document.body.clientWidth:null);
    var wh=(imgWndw.innerHeight)?imgWndw.innerHeight:((document.body)?
      imgWndw.document.body.clientHeight:null);
		if (/gecko/i.exec(navigator.userAgent)) ww-=50;
    if (ww && wh) {
      imgWndw.resizeBy(w-ww,h-wh);
    }
    imgWndw.focus();
    clearInterval(resId)
  }
}

// Функция установки значения cookie.
// name      - имя cookie
// value     - значение cookie
// [path]    - путь, для которого cookie действительно (по умолчанию - /)
// [expires] - дата окончания действия cookie (по умолчанию - до конца сессии)
// [domain]  - домен, для которого cookie действительно (по умолчанию - домен,
//             в котором значение было установлено)
// [secure]  - логическое значение, показывающее требуется ли защищенная
//             передача значения cookie
function setCookie(name, value, path, expires, domain, secure) {
  var curCookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "; path=/") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// Функция чтения значения cookie.
// name - имя считываемого cookie
function getCookie(name) {
  var prefix = name + "=";
  var cookieStartIndex = document.cookie.indexOf(prefix);
  if(cookieStartIndex == -1) return null;
  var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
  if(cookieEndIndex == -1) cookieEndIndex = document.cookie.length;
  return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

// Функция удаления значения cookie
// name - имя cookie
// [path] - путь, для которого cookie действительно
// [domain] - домен, для которого cookie действительно
function delCookie(name, path, domain) {
  if(getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "; path=/") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// Устанавливает Cookie сложной структуры.
function setCookieEx(name, value, path, expires, domain, secure)
{ value=Serialize(value);
//  alert(value);
  return setCookie(name, value, path, expires, domain, secure);
}

// Читает Cookie сложной структуры.
function getCookieEx(name)
{ var v=getCookie(name);
  return Unserialize(v);
}
