var search,input_search,delivery,input_delivery,detect,flash_name='index',flash_mode='window',current_img;
var mail_check=new RegExp(/^(\w+[\w_-]*\.*)*[\w]+@[a-z0-9]+([a-z0-9-]*[a-z0-9]+)*\.[a-z]{2,}$/);

function flash_inner(e){
  flash_name=e;
}

function flash_test(){
  detect=document.createElement('div');
  detect.id='flash_detect';
  document.body.appendChild(detect);
  flash_innerhtml(detect,'detect');
}

function flashDetect(){
  //var test=new RegExp('^.+'+location.hostname+'\/([^\/]+)\/.*$');
  var element=document.getElementById('flash');
  if(element && flash_name != ''){
    /*if(test.test(location)){
      //flash_name=test.exec(location)[1];
      flash_mode='transparent';
    }*/
    if(flash_name!='index')flash_mode='transparent';
    else element.className='';
    flash_innerhtml(element,flash_name,flash_mode);
  }
  if(document.getElementById('music')){
    var object_parameters='<param name="FlashVars" value="playlist=/player.xml&autostart=false">';
    var embed_parameters=' FlashVars="playlist=/player.xml&autostart=false"';
    flash_innerhtml(document.getElementById('music').getElementsByTagName('div')[0],'player',flash_mode,object_parameters,embed_parameters);
  }
}

function flash_innerhtml(element,name,mode,object_parameters,embed_parameters){
  object_parameters=object_parameters||'';
  embed_parameters=embed_parameters||'';
  mode=mode||'window';
  element.innerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100%" height="100%"><param name="allowScriptAccess" value="sameDomain"><param name="movie" value="/i/flash/'+name+'.swf"><param name="quality" value="high"><param name="bgcolor" value="#000000" ><param name="wmode" value="'+mode+'">'+object_parameters+'<embed src="/i/flash/'+name+'.swf" quality="high" bgcolor="#000000" wmode="'+mode+'" allowScriptAccess="sameDomain" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="100%" height="100%"'+embed_parameters+'></embed></object>';
}


window.onload=function(){
  form_word();
  flash_test();
  var parent=document.getElementById('list');
  if(parent&&document.attachEvent){
    parent.onmouseover=over;
    parent.onmouseout=out;
    var li=parent.getElementsByTagName('li');
    for(var i=0;li[i];i++){
      li[i].onmouseover=over;
      li[i].onmouseout=out;
      /*li[i].attachEvent('onmouseover',over);
      li[i].attachEvent('onmouseout',out);*/
    }
  }

  //if(document.getElementById('short'))document.getElementById('short').className='main';
}



function over(){
  this.className='on';
}

function out(){
  this.className='';
}

document.onclick=function(e){
  e=e||event;
  var target=e.target||e.srcElement;
  if(target.tagName=='INPUT'&&target.name=='country'){
    if(target.value==2){
    //  document.getElementById('detail').className='none';
	document.getElementById('Region').disabled=true;

      target.form.country_other.disabled=false;
      target.form.country_other.focus();
    }
    else{
      target.form.country_other.disabled=true;
      document.getElementById('detail').className='';
      if(c = document.getElementById('Region')) { c.disabled=false; }
    }
  }
  else if(target.tagName=='IMG'&&target.parentNode.tagName=='A'/*&&target.parentNode.target=='_blank'*/){
    if(/jpe?g$/.test(target.parentNode.href)||/gif$/.test(target.parentNode.href)){
      current_img=target.parentNode.href;
      window_open(target);
      return false;
    }
    else if(/\/gallery\//.test(target.parentNode.href) || /\/parade\/photo\//.test(target.parentNode.href)){
      window_open(target,target.parentNode.href);
      return false;
    }
  }
  else if(target.tagName=='A'&&target.target=='_blank'){
    if(/\/map\//.test(target.href)){
      window_open(target,target.href);
      return false;
    }
    else if(/jpg$/.test(target.href)){
      current_img=target.href;
      window_open(target);
      return false;
    }
  }
}

function window_open(e,path){
  path=path||'/popup/index.html';
  var my_width=e.getAttribute('x')?(e.getAttribute('x')*1+100):900;
  var my_height=e.getAttribute('y')?(e.getAttribute('y')*1+260):800;
  var screen_width=screen.availWidth;
  var screen_height=screen.availHeight;
  var my_left=screen_width>my_width?(screen_width-my_width)/2:0;
  var my_top=screen_height>my_height?(screen_height-my_height)/2:0;
  var parameters='width='+my_width+',height='+my_height+',top='+my_top+',left='+my_left+',scrollbars=1,titlebar=0,toolbar=0,menubar=0';
  new_window=window.open(path,'',parameters);
  new_window.focus();
}

function form_word(){
  if(search=document.search){
    search.onsubmit=check_form;
    input_search=search.text;
    input_search.defaultValue=input_search.value;
    input_search.onfocus=on_word;
    input_search.onblur=out_word;
  }
  if(delivery=document.delivery){
    delivery.onsubmit=check_form;
    input_delivery=delivery.email;
    input_delivery.defaultValue=input_delivery.value;
    input_delivery.onfocus=on_word;
    input_delivery.onblur=out_word;
  }
}
function on_word(){
  if(this.value==this.defaultValue){
    this.value='';
  }
  else this.select();
}
function out_word(){
  if(/^\s*$/.test(this.value)){
    this.value=this.defaultValue;
  }
}
function check_form(){
  if(this==search){
    flag=(input_search.value==''||input_search.value==input_search.defaultValue)?false:true;
  }
  if(this==delivery){
    flag=/^(\w+[\w_-]*\.*)*[\w]+@[a-z0-9]+([a-z0-9-]*[a-z0-9]+)*\.[a-z]{2,}$/.test(input_delivery.value);
    if(!flag){
      if(input_delivery.value==''||input_delivery.value==input_delivery.defaultValue)alert('Не заполнен e-mail');
      else alert('Неправильно заполнен e-mail');
    }
  }
  return flag;
}

function check_region(e){
  var uri=location.href.substring(0,location.href.indexOf('?'));
  if(e.value!=1)location=uri+'?region='+e.value;
  else location=uri;
}