function goArticlesCat(){
    if(document.selecter.select1.options[document.selecter.select1.selectedIndex].value != "none"){
        location =document.selecter.select1.options[document.selecter.select1.selectedIndex].value
    }
}

host = 'http://'+location.host;
path = host+'/data/img/'; 
imglist = new Array;
var old_image;

//---------------------------------------------------------------------------------------// 

function display_menu(id){ 

  for(i=0; i<=7; i=i+1){
    lt = 'menu'+i;
    if(id == i) continue;  
    
    if(document.getElementById && document.getElementById(lt)){
     itema = document.getElementById(lt);
     itema.style.display = 'none';
     itema.style.backgroundColor = '#f0f0f1'; 
    }
  }
    
  child = document.getElementById('menu'+id);
  main = document.getElementById('head'+id);
  main.style.backgroundColor = '#f0f0f1';
  content = main.innerHTML;
      
  if(child.style.display == 'none'){
    child.style.display = 'block';
    content = content.replace('+', '–');
  }
  else{
    child.style.display = 'none';
    content = content.replace('–', '+');
  }
  
  main.innerHTML = content;   
  return false;
}

//---------------------------------------------------------------------------------------// 

function preload_images() {
  if (document.images) {

    for(i=1; i<=7; i++){ 
      imglist[i] = new Image(); 
      imglist[i].src = host + "/data/img/menu/"+i+"_on.jpg"; 
    }
  } 
}

//---------------------------------------------------------------------------------------// 

function change_menu(id, type){

  if(type){
    old_image = document.images['menu'+id].src;
    document.images['menu'+id].src = imglist[id].src; 
  }
  else
    document.images['menu'+id].src = old_image;  
}

//---------------------------------------------------------------------------------------// 

function change_bg(type, id, ison){

  obj = document.getElementById(type+id);
  
  if(ison){
    if(type == 'head') obj.style.backgroundColor = '#f8f8f8';
    else obj.style.backgroundColor = '#cee3f7';
  }
  else{
    if(type == 'head') obj.style.backgroundColor = '#f0f0f1';
    else obj.style.backgroundColor = '#ffffff';
  }
}

//---------------------------------------------------------------------------------------// 

function display_cat_menu(id){ 
  mid = 'menu'+id
  hid = 'head'+id
  
  if(document.getElementById && document.getElementById(mid)){
    obj1 = document.getElementById(mid);
    obj1.style.display = (obj1.style.display == 'none' ) ? 'block' : 'none';
  } 
  
  if(document.getElementById(hid)){
    obj2 = document.getElementById(hid);
    
    if(obj1.style.display == 'none'){
      obj2.className =  'bg_noneheader';
      obj2.innerHTML= obj2.innerHTML.replace('-','+');
    }
    else{
      obj2.className = 'bg_header';     
      obj2.innerHTML= obj2.innerHTML.replace('+','-');
    }
  }
  
  return false;
}

//---------------------------------------------------------------------------------------// 

function display_panel(){
  if(document.getElementById && document.getElementById('search_panel')){
    obj = document.getElementById('search_panel');
    obj.style.display = (obj.style.display == 'none' ) ? 'block' : 'none';
  }
}

//---------------------------------------------------------------------------------------// 
      
function select_all(form)
{
   sample_check = document.getElementById('checklist').checked;
   
   for (i = 0; i < form.elements.length; i++){
     if (form.elements[i].name=='items[]') form.elements[i].checked = sample_check;
   }
}
    
//---------------------------------------------------------------------------------------//
   
function update_selects(cat_active, subcat_active) {
  var first_select = document.getElementById("country_id");
  var second_select = document.getElementById("city_id");
  
  if(!first_select.options.length){
    first_select.options[0] = new Option('All', 0); 
    
    for (var i=0; i<countries.length; i++){
      subs = countries[i].split(':');
      first_select.options[i+1] = new Option(subs[1], subs[0]);
      
      if(subs[0] == cat_active)
        first_select.options[i+1].selected = true;
    }
  }
  
  var choice = first_select.options[first_select.selectedIndex].value;
  var db = cities[choice];
  
  second_select.options.length = 0;
  
  if (choice != ""){
    second_select.options[0] = new Option('All', 0); 
    for (var i=0; i<db.length; i++) {
      subs = db[i].split(':');
      second_select.options[i+1] = new Option(subs[1], subs[0]);

      if(subs[0] == subcat_active)
        second_select.options[i+1].selected = true;
    }
  }
}    

//---------------------------------------------------------------------------------------//    
	
function im(path, title){
  host = 'http://'+location.hostname+'/';
  window.open(host+'catalog/image.html?path='+path+'&title='+title,'','width=100, height=100, scrollbars=no');		
}	

//---------------------------------------------------------------------------------------//

function goto_pr() {
  select_box = document.pform.prlist;
  eval("parent.location='"+select_box.options[select_box.selectedIndex].value+"'");
  return false;
  
}

//---------------------------------------------------------------------------------------//
	
function sethome(o,siteurl,sitename) {
	var name = navigator.appName;
	var useragent = navigator.userAgent;
	var version = parseInt(navigator.appVersion);
	var needtoknow = 1;
	
	if ( useragent.indexOf("MSIE") != -1) {
			var index = navigator.userAgent.indexOf("MSIE ");
			if ( index != -1 ) {
				version = parseInt(navigator.userAgent.substring(index+5,index+6));
			}
			if ( version > 4) {
				o.style.behavior='url(#default#homepage)'; o.setHomePage(siteurl);
				needtoknow = 0;
			}
	}
	if (needtoknow != 0) {
		alert('Ваш браузер не поддерживает автоматической установки стартовой страницы')
		//openBrWindow('/help/makehomepage.html','winMakeHomepage','location=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=450');
	}
}
   
//---------------------------------------------------------------------------------------//
   
var old_image;

function on_image(id){
  if(document.images){
    old_image = document.images['img_main'].src;
    document.images['img_main'].src = image_array[id].src; 
  }
}

//---------------------------------------------------------------------------------------//

function out_image(id){
  if(document.images){
    document.images['img_main'].src = old_image; 
  }
}

//---------------------------------------------------------------------------------------// 
var timeout_id;
var times = 0;

function show_block(){
  if(document.getElementById && document.getElementById('addinfo')){
    obj = document.getElementById('addinfo');
    display = (obj.style.display == 'none' ) ? 'block' : 'none';
    
    ctop = screen.height/2 - 100 + document.documentElement.scrollTop;
    cleft = document.body.clientWidth/2 - 100 + document.documentElement.scrollLeft;
    
    obj.style.cssText = 'position:absolute; display:'+display+'; left:'+cleft+'px; top:'+ctop+'px; width:200px; height: 60px;';
  } 
  
  timeout_id = setInterval("hide_block()", 1000);
}

//---------------------------------------------------------------------------------------// 

function action_form(myForm, action){  
  myForm.act.value = action;
  myForm.submit(); 
  return false;
}

//---------------------------------------------------------------------------------------//

function jumpMenu(myForm, selObj) {
  myForm.act.value = 'change';
  myForm.id.value = selObj.options[selObj.selectedIndex].value;
  myForm.submit(); 
  return false;
}

//---------------------------------------------------------------------------------------//

function getBrowserInfo() 
{
    var t,v = undefined;
    if (window.opera) t = 'Opera';
    else if (document.all) 
    {
        t = 'IE';
        var nv = navigator.appVersion;
        var s = nv.indexOf('MSIE')+5;
        v = nv.substring(s,s+1);
    }
    else if (navigator.appName) t = 'Netscape';
    return {type:t,version:v};
}

//---------------------------------------------------------------------------------------//

function bookmark(a)
{
    var url = window.document.location;
    var title = window.document.title;
    var b = getBrowserInfo();
    if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
    else if (b.type == 'Opera') 
    {
        a.href = url;
        a.rel = "sidebar";
        a.title = url+','+title;
        return true;
    }
    else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
    else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
    return false;
}

//---------------------------------------------------------------------------------------//

function showSubMenu(name)
{
    if(document.getElementById(name).style.display == 'none') document.getElementById(name).style.display = 'block'; else document.getElementById(name).style.display = 'none';    
}

//---------------------------------------------------------------------------------------//

function image_reload(version)
{
    document.images['captcha_'+version].src='/captcha_'+version+'.php?rnd='+Math.round(Math.random(0)*1000);
}

//---------------------------------------------------------------------------------------//

function smile(str){
    obj = document.gooestform.message;
    obj.focus();
    obj.value =    obj.value + str;
}

function open_window(link,w,h) //opens new window
{
    var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
    newWin = window.open(link,'newWin',win);
    newWin.focus();
}
$(function() {
    $("a#first").fancybox({
            'opacity'        : true,
            'overlayShow'    : false,
            'transitionIn'   : 'elastic',
            'transitionOut'  : 'none'
    });    
    $("a[rel=example_group]").fancybox({
            'transitionIn'   : 'none',
            'transitionOut'  : 'none',
            'titlePosition'  : 'over',
            'titleFormat'    : 'none'
            /*'titleFormat'        : function(title, currentArray, currentIndex, currentOpts) {
                return '<span id="fancybox-title-over">Фото ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' <br><br>' + title : '') + '</span>';
            }*/
    });
    $('a#various').fancybox({
        'titlePosition'      : 'none',
        'transitionIn'       : 'none',
        'transitionOut'      : 'none'
    });
    
});

function goTop() 
{
    $('html, body').animate({scrollTop:0}, 'slow');
}

