//  MescalDesign & MescalArt - complete solutions for internet
//  contact methods:
//  site:  www.mescaldesign.pl
//  email: biuro@mescaldesign.pl
//  phone: +48 501 109 137
//  MescalDesign 2011 (c) All rights reserved

var mescal = {};

mescal.menuHoverMethods = function(item) {
  var image, id, src_orig, src_hover, methods, zidx;
  zidx      = $(item).css('z-index');
  
  image     = $("img",item);
  id        = $("a",item).attr("data-id");
  src_orig  = "/images/" + id + "but.png";
  src_hover = "/images/" + id + "buth.png";
  var methods = {
    hover   : function() { 
                $(image).attr("src",src_hover); 
                $(item).css({'z-index' : 10});
              },
    unhover : function() { 
                $(image).attr("src",src_orig);  
                $(item).css({'z-index' : 7-id});
              }
  };
  return methods;
}

mescal.leftmenu = function(item) {
  var methods = {
  hover   : function() { 
                $(item).stop().animate({
                  'backgroundPosition' : '7px 10'
                }, 50);
              },
  unhover : function() { 
                $(item).stop().animate({
                  backgroundPosition: '3px 10'
                }, 200);
              }
  };
  return methods;
}

mescal.menu_click_show = function(item) {
  item = $(item).parent();
  var subitems, subitemsli;
  subitems  = $(".submenu",item);
  subitemsli  = $(".submenu li",item);
  subitems.animate({
      height: 'show', 
      opacity: 'show',
    }, 500
  );
  subitemsli.each(function() {
    $(this).animate({
      'opacity' : '0.9',
      'background' : 'red'
    });
    /*
    $("#top_left nav>*").css({ 
      'z-index' : '9999'
    });
    */
  });
  return null;
}
mescal.menu_click_hide = function(item) {
  item = $(item).parent();
  var subitems;
  subitems  = $(".submenu",item);
  subitems.animate({
      height: 'hide', 
      opacity: 'hide'
    }, 300
  );
  return null;
}

mescal.menu_hover = function() {
  $("#menu li:not(.selected)").hover(
    function() { mescal.menuHoverMethods(this).hover(); },
    function() { mescal.menuHoverMethods(this).unhover(); }
  );
  return null;
}
mescal.leftmenu_hover = function() {
  $(".leftmenu a:not(.selected)").hover(
    function() { mescal.leftmenu(this).hover(); },
    function() { mescal.leftmenu(this).unhover(); }
  );
  return null;
}



mescal.companies_hover = function() {
  $("#cooperation ul li:not(.selected)").hover(
    function() { mescal.companies_hover_actions(this).hover(); },
    function() { mescal.companies_hover_actions(this).unhover(); }
  );
  return null;
}

mescal.menu_click = function() {
  $("#menu li").toggle(
      function() { 
        mescal.menu_click_hover(this); 
      },
      function() { 
        mescal.menu_click_unhover(this); 
      }
  );
  return null;
}

mescal.menu_fold = function() {
  $("#menu_title").click(function() {
    var submenus = $("ul.submenu");
    submenus.each(function() {
      $(this).animate({
        height: 'hide', 
        opacity: 'hide'
      },200);
    });
  mescal.menu_click();
  });
}
mescal.offer_click = function() {
  $(".offer .offertitle").toggle(
    function() { mescal.offer_click_show(this); },
    function() { mescal.offer_click_hide(this); }
  );
  return null;
}

mescal.offer_click_show = function(item) {
  var subitems;
  subitems  = $(".suboff",item);
  subitems.animate({
      height: 'show', 
      opacity: 'show',
  }, 500);
  return null;
}
mescal.offer_click_hide = function(item) {
  var subitems;
  subitems  = $(".suboff",item);
  subitems.animate({
      height: 'hide', 
      opacity: 'hide'
    }, 300
  );
  return null;
}

mescal.column_height = function() {
  var content_height, cooperation_height, columns_height;
  content_height = $("#content").height();
  cooperation_height = $("#cooperation").height();
  columns_height = content_height - cooperation_height - 145;
  $(".columns").height(columns_height);
}
mescal.banners_rotate = function() {
	$('#banners').totemticker({
	  row_height	:	'76px',
    mousestop	:	true,
    max_items   : 3,
    direction	:	'up'
	});
}

$(document).ready(function() {
  mescal.menu_hover();
  mescal.leftmenu_hover();
  mescal.column_height();
  mescal.banners_rotate();
  $(".gpic a").fancybox({
  'titlePosition' : 'over'
  });
});

