// komi-typo JavaScript Document

/* DataArray for Expo(Vitrina), arbitrary length */
/*var expoData = new Array();
expoData[0] = {src:'./gfx/decor/expo-image1.jpg', text:'Многостраничные издания'}
expoData[1] = {src:'./gfx/decor/expo-image2.jpg', text:'Рекламная продукция'}
expoData[2] = {src:'./gfx/decor/expo-image3.jpg', text:'Офисная и представительская продукция'}
expoData[3] = {src:'./gfx/decor/expo-image4.jpg', text:'Периодические издания'}*/

/* Expo-change-visualization routine */

function downloadFile(file) {
  var f = confirm('Вы действительно хотите скачать прайс-лист?');
  if (f == true) {
    window.location = file;
  }
}

function changeExpoByIndex(i){
  $(".mExpoNext img").attr({src:expoData[i].src, alt:expoData[i].text});
  $(".mExpoText").attr({title: expoData[i].text, href: expoData[i].link}).text(expoData[i].text);
  $(".placeForLink a").attr("href",expoData[i].link);
  $(".mExpoDial .mExpoActive").removeClass("mExpoActive");
  $(".mExpoDial a").eq(i).addClass("mExpoActive");
}

/* Binding all Event-handlers */
function AllBind(){
  /* search form get and lost focus */
  $("#searchForm input").focus(function(){
    $(this).parents("form").addClass("focus");
  }).blur(function(){
    $(this).parents("form").removeClass("focus");
  });
  /* window.expo stores the index of current Expo frame */
  window.expo = Math.floor(Math.random()*(expoData.length-0.001)); 
  
  expoDial = $(".mExpoDial");
  for (i = 0; i < expoData.length; i++) {
    expoDial.append("<a href='#e"+(i+1)+"' title='"+expoData[i].text+"'>&nbsp;</a>");
  }
  
  changeExpoByIndex(window.expo);
  /* handle mExpoArrows click */
  setInterval("$('.mExpoArrow.mExpoRight').trigger('click');", 5000);
  $(".mExpoArrow").click(function(){
    if($(this).is(".mExpoLeft")){
      window.expo = (window.expo>0)? window.expo - 1 : expoData.length - 1;
    } else {
      window.expo = (window.expo < expoData.length-1)? window.expo + 1 : 0;
    }
    changeExpoByIndex(window.expo);
    $(this).blur();
    return false
  });
  /* handle mExpoDial click */
  $(".mExpoDial a").click(function(event){
    $(".mExpoDial .mExpoActive").removeClass("mExpoActive");
    $(this).addClass("mExpoActive").blur();
    for(var i = 0; i<expoData.length; i++){
      if($(".mExpoDial a").eq(i).is(".mExpoActive")){ window.expo = i; changeExpoByIndex(window.expo); break }
      continue
    }
    return false
  });
};

function showGoods() {
  $('.visualSmallWindow').hide();
  $('.mRightGoods h2 a').click(function() {
    getProduction(this);
    $('.visualSmallWindow').fadeIn("slow");
    return false;
  });
  $('.closeBlock div').click(function() {
    $('.visualSmallWindow').fadeOut("slow");
    return false;});
  }

function productHoverBinding() {
  $('.placeForPic a').bind('mouseenter mouseleave',
    function() {
      var imgPath = $(this).css('background-image');
      $(this).css('background-image',$(this).attr('rel'));
      $(this).attr('rel',imgPath);
    });
}
function onclickProductBinding() {
  $('.visualSmallBlock a').bind('click',function() {getProduction(this); return false;});            
}
function getProduction(obj) {
  da_getProduction($(obj).attr('id'));
}

function clearVitrina(a) {
  var height = 195;
  var a = new Array("развернуть витрину","свернуть витрину");
  var i = 0;
  function flip(flipType){
    if (flipType == 0){
      $('body').addClass('hideVitrina');
      //$("#header-wrap").css("height", height);
      //$('.hClearVitrina .one').hide();
      //$('.hClearVitrina .two').show();
      $.cookie('hideVitrina', 1, {path:'/'});
    } else {
      //$('.hClearVitrina .two').hide();
      //$('.hClearVitrina .one').show();
      $.cookie('hideVitrina', 0, {path:'/'});
    }
  }

  $(".hClearVitrina .hideV").click(function() {
    if(i == 0) {
      i = 1;
      $('.mExpoWrap').slideUp('fast', function(){ flip(0) } );
      $(this).html(a[0]);
    } else {
      i = 0;
      $('.mExpoWrap').slideDown('fast', function(){ flip(1) } );
      $('body').removeClass('hideVitrina');
      $(this).html(a[1]);
      //$("#header-wrap").css("height", "");
    }
    return false;
  });
  //$('.hClearVitrina .two').hide();
  var hideVitrina = $.cookie('hideVitrina');
  if (hideVitrina == 1) $(".hClearVitrina .hideV").click();


/*  $('.hClearVitrina .one').click(function() {
    if(i == 0) {
      i = 1;
      buttonValue = a[0];
      $('.mExpoWrap').hide();
    }
    $("#header-wrap").css("height", height);
    $('.hClearVitrina input').val(buttonValue);
  });

  $('.hClearVitrina .two').click(function() {
    if(i == 1) {
      i = 0;
      buttonValue = a[1];
      $('.mExpoWrap').show();
      height = "";
    }   
    $("#header-wrap").css("height", height);
    $('.hClearVitrina input').val(buttonValue);
  });*/
}

function toggleMap() {
  $('#sitemap-wrap h2 a').click( function() {
    $('#sitemap').toggle();
    return false;
  });
}
 

function checkDemandForm() {
  var form = $("form.demandForm");
  var message = new Array();
  
  if ($.trim(form.find("[name='person']").val()) == '') message.push("контактное лицо");
  if ($.trim(form.find("[name='phone']").val()) == '') message.push("контактный телефон");
  if ($.trim(form.find("[name='products']").val()) == '') message.push("интересующая продукция");
  
  message.length ? alert('Заполните следующие поля: ' + message.join(", ")) : form.submit();
}
