/*
 * Droppy 0.1.2
 * (c) 2008 Jason Frame (jason@onehackoranother.com)
 */
(function($) {
  
  jQuery.fn.droppy = function(options) {

    options = jQuery.extend({speed: 250, className: 'droppy', trigger: 'hover'}, options || {});

    this.each(function() {

      var root = this, zIndex = 1000;

      jQuery(root).addClass(options.className);
			jQuery(root).find('li:has(> ul) > a').addClass('has-subnav');

      function getSubnav(ele) {
        if (ele.nodeName.toLowerCase() == 'li') {
          var subnav = jQuery('> ul', ele);
          return subnav.length ? subnav[0] : null;
        } else {
          return ele;
        }
      };

      function getActuator(ele) {
        if (ele.nodeName.toLowerCase() == 'ul') {
          return jQuery(ele).parents('li')[0];
        } else {
          return ele;
        }
      };

      function hide() {
        var subnav = getSubnav(this);
        if (!subnav) return;
        jQuery.data(subnav, 'cancelHide', false);
        setTimeout(function() {
          if (!jQuery.data(subnav, 'cancelHide')) {
            jQuery(subnav).slideUp(options.speed);
          }
        }, 500);
      };

      function show() {
        var subnav = getSubnav(this);
        if (!subnav) return;
        jQuery.data(subnav, 'cancelHide', true);
        jQuery(subnav).css({zIndex: zIndex++}).slideDown(options.speed);
        if (this.nodeName.toLowerCase() == 'ul') {
          var li = getActuator(this);
          jQuery(li).addClass('hover');
          jQuery('> a', li).addClass('hover');
        }
        return false;
      };
      
      if (options.trigger == 'click') {
        jQuery('> li', this).click(show);
        jQuery('> li ul, > li li', this).hover(show, function() {});
        jQuery('ul, li', this).hover(function() {}, hide);
      } else {
        if (typeof jQuery.fn.hoverIntent == 'function') {
          jQuery('ul, li', this).hoverIntent(jQuery.extend({
            sensitivity: 2, interval: 50, timeout: 100
          }, options.hoverIntent || {}, {over: show, out: hide}));
        } else {
          jQuery('ul, li', this).hover(show, hide);
        }
      }
      
      jQuery('li', this).hover(
        function() { jQuery(this).addClass('hover'); jQuery('> a', this).addClass('hover'); },
        function() { jQuery(this).removeClass('hover'); jQuery('> a', this).removeClass('hover'); }
      );

    });

  };

})(jQuery);

var dropx;
var theform;
//menu sub navigation
jQuery(document).ready(function(){
	jQuery('#topmenu').droppy();		   
	jQuery('.rootnav.has-subnav').each(function () {
		jQuery(this).removeClass('rootnav');
		jQuery(this).parent().addClass('rootnav2');
	});
	dropx = document.getElementById('dropx');
	theform = document.forms["theform"];
});

// hide boxes on full width page
jQuery(document).ready(function(){
 jQuery('a[href*=#]').click(function() {
 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
 && location.hostname == this.hostname) {
   var jQuerytarget = jQuery(this.hash);
   jQuerytarget = jQuerytarget.length && jQuerytarget
   || jQuery('[name=' + this.hash.slice(1) +']');
   if (jQuerytarget.length) {
  var targetOffset = jQuerytarget.offset().top;
  jQuery('html,body')
  .animate({scrollTop: targetOffset}, 1000);
    return false;
   }
 }
  });
jQuery('.close').click(function() {
  jQuery(this).parent('.box').fadeOut('slow');
});

});

//show and hide left menu
jQuery(document).ready(function(){
jQuery('.show_left_div').click(function() { 
  jQuery(this).toggleClass("right_arrow").toggleClass("left_arrow");
  jQuery(".hidden_left_div").animate({width: ['toggle', 'swing']}, 'medium');

	});

});

//change background
if(jQuery.cookie("css")) {
	jQuery("#bg").attr("href",jQuery.cookie("css"));
}
jQuery(document).ready(function() { 
	jQuery("#nav li a").click(function() { 
		jQuery("#bg").attr("href",jQuery(this).attr('rel'));
		jQuery.cookie("css",jQuery(this).attr('rel'), {expires: 365, path: '/'});
		return false;
	});
});
