﻿var glob_path = ''

Shadowbox.loadSkin('classic', glob_path + '/js/shadowbox/skin');
Shadowbox.loadLanguage('en', glob_path + '/js/shadowbox/lang');
Shadowbox.loadPlayer(['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'], glob_path + '/js/shadowbox/player');
$(window).load(function(){
  var options = {};
  Shadowbox.init(options);
});

var on = 0;

var act= 0;

var text = '';

var searchq = '';

$(function(){

  /* Cart products ************************************************************/
  $('.prod_buy a, .p_tobascet a.tobascet').click(function(){
    var id = this.id.split('_')[1];
    $.post(
      glob_path+'/shop/add-to-cart.html',
      {'product_id' : id},
      function(data){$('#cart_list').html(data); }
    );
    return false;
  });

  $('#clear_cart').click(function(){
    $.post(
      glob_path+'/shop/remove-from-cart.html',
      {'product_id' : 0},
      function(data){$('#cart_list').html(data); }
    );
    return false;
  });

  $("#showchers").click(function(){
    $("#chers").toggle();
  });

  $("#search-result").mouseover(function () {
if(act == 1){
       $(this).css('display','block');
}
on = 1;
  }).mouseout(function () {
if(act == 0){
       $(this).css('display','none');
}
on = 0;
  });
  

  $("#searchq").blur(function(){
   if(on==0){
     $("#search-result").slideUp();
     if(searchq==""){$(this).attr("value","введите слово для поиска...");}
   }	
   act = 0;
  }).focus(function(){ 
   act = 1;
   $(this).attr("value",searchq);
   if(text!=""){
     $("#search-result").slideDown("400");
   }
  });

  $(".row0,.row1").mouseover(function(){
  	$(this).addClass('trover');
  }).mouseout(function(){
  	$(this).removeClass('trover');
  });

  $("#searchq").keyup(function(){
    if($(this).attr("value")==''){$("#search-result").slideUp();}
    searchq = $(this).attr("value");
    nocache = Math.random();
    $.get(glob_path + '/shop/aj_search.html?name='+encodeURI(searchq)+'&nocache = '+nocache,function(data){
      text=data;
      if(text!=''){$("#search-content").html(text); $("#search-result").slideDown("400");}else{$("#search-result").slideUp();}
    });
	
  });
});

  function geturl()
  {
	if(searchq!=""){
	  self.location=glob_path + '/shop/search/' + encodeURIComponent(document.getElementById('searchq').value) + '/name-asc/1.html';
	}
  }
function remove_from_cart(id, reload)
{
    $.post(
      glob_path+'/shop/remove-from-cart.html',
      {'product_id' : id},
      function(data){
        $('#cart_list').html(data);
        if(reload == true){window.location = window.location;}
      });
}

$.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    $("<img>").attr("src", arguments[i]);
  }
}

$.preloadImages(glob_path + '/images/menu_first_a.gif', glob_path + '/images/menu_mid_a.gif', glob_path + '/images/menu_mid1_a.gif', glob_path + '/images/menu_last_a.gif');


/* -------------------------- */
/*   XMLHTTPRequest Enable    */
/* -------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
} else {
request_type = new XMLHttpRequest();
}
return request_type;
}

function searchNameq() {
searchq = encodeURI(document.getElementById('searchq').value);

document.getElementById('msg').innerHTML = "Searching for <strong>" + searchq+"";
// Set te random number to add to URL request
nocache = Math.random();
http.open('get', glob_path + '/shop/aj_search.html?name='+searchq+'&nocache = '+nocache);
http.onreadystatechange =  searchNameqReply;
http.send(null);
$("#search-result").slideDown("600");
}
var http = createObject();

/* -------------------------- */
/*        SEARCH              */
/* -------------------------- */

function searchNameqReply() {
if(http.readyState == 4){
var response = http.responseText;
document.getElementById('search-result').innerHTML = response;
}
}