/*
  $Id: general.js,v 1.1.1.1 2004/03/04 23:40:38 ccwjr Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

function SetFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName != "") {
    for (var i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target = i;
        break;
      }
    }
  }

  var TargetForm = document.forms[target];
    
  for (var i=0; i<TargetForm.length; i++) {
    if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) {
      TargetForm.elements[i].focus();

      if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) {
        TargetForm.elements[i].select();
      }

      break;
    }
  }
}

function RemoveFormatString(TargetElement, FormatString) {
  if (TargetElement.value == FormatString) {
    TargetElement.value = "";
  }

  TargetElement.select();
}

function CheckDateRange(from, to) {
  if (Date.parse(from.value) <= Date.parse(to.value)) {
    return true;
  } else {
    return false;
  }
}

function IsValidDate(DateToCheck, FormatString) {
  var strDateToCheck;
  var strDateToCheckArray;
  var strFormatArray;
  var strFormatString;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var intDateSeparatorIdx = -1;
  var intFormatSeparatorIdx = -1;
  var strSeparatorArray = new Array("-"," ","/",".");
  var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  strDateToCheck = DateToCheck.toLowerCase();
  strFormatString = FormatString.toLowerCase();
  
  if (strDateToCheck.length != strFormatString.length) {
    return false;
  }

  for (var i=0; i<strSeparatorArray.length; i++) {
    if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
      intFormatSeparatorIdx = i;
      break;
    }
  }

  for (var i=0; i<strSeparatorArray.length; i++) {
    if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
      intDateSeparatorIdx = i;
      break;
    }
  }

  if (intDateSeparatorIdx != intFormatSeparatorIdx) {
    return false;
  }

  if (intDateSeparatorIdx != -1) {
    strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
    if (strFormatArray.length != 3) {
      return false;
    }

    strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
    if (strDateToCheckArray.length != 3) {
      return false;
    }

    for (var i=0; i<strFormatArray.length; i++) {
      if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') {
        strMonth = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'dd') {
        strDay = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'yyyy') {
        strYear = strDateToCheckArray[i];
      }
    }
  } else {
    if (FormatString.length > 7) {
      if (strFormatString.indexOf('mmm') == -1) {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
      } else {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
      }

      strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2);
      strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2);
    } else {
      return false;
    }
  }

  if (strYear.length != 4) {
    return false;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    return false;
  }
  if (intday < 1) {
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (var i=0; i<strMonthArray.length; i++) {
      if (strMonth == strMonthArray[i]) {
        intMonth = i+1;
        break;
      }
    }
    if (isNaN(intMonth)) {
      return false;
    }
  }
  if (intMonth > 12 || intMonth < 1) {
    return false;
  }

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    return false;
  }
  if (IsLeapYear(intYear) == true) {
    intDaysArray[1] = 29;
  }

  if (intday > intDaysArray[intMonth - 1]) {
    return false;
  }
  
  return true;
}

function IsLeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) {
      return true;
    }
  } else {
    if ((intYear % 4) == 0) {
      return true;
    }
  }

  return false;
}

function clickclear(thisfield, defaulttext) {
  if (thisfield.value == defaulttext) {
    thisfield.value = "";
  }
}
 
function clickrecall(thisfield, defaulttext) {
  if (thisfield.value == "") {
   thisfield.value = defaulttext;
  }
}

function addLoadEvent(func) { 
  var oldonload = window.onload; 
  if (typeof window.onload != 'function') { 
	    window.onload = func; 
	  } else { 
	    window.onload = function() { 
	      if (oldonload) { 
	        oldonload(); 
	      } 
	      func(); 
	    } 
	  } 
	} 


function disableSelection(target){
    if (typeof target.onselectstart!="undefined") //IE route
        target.onselectstart=function(){return false}
    else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
        target.style.MozUserSelect="none"
    else //All other route (ie: Opera)
        target.onmousedown=function(){return false}
    target.style.cursor = "default"
}

Snurrbanner = new (function() {

    this.steps = 5;       /* number of opacity intervals   */
    this.delay = 1000;     /* 5 sec delay before fading out */
    this.timer = null;
    this.op_diff = 1/this.steps;
    this.fade_direction = 1; //-1 fadeout, 1 fadein, 0=hanging out
    this.cur_rolling = 0;
    this.between_fade_delay=5000;
    this.on_button_mouseover=false;
    this.next_rolling=false;
    this.num_rollings;
    this.snurrbanner_is_mouseover=false;

    this.init = function() {
        this.next_rolling=false;
        this.fade_direction = 1; //-1 fadeout, 1 fadein, 0=hanging out
        this.cur_rolling = 0;
        this.on_button_mouseover=false;
        this.snurrbanner_is_mouseover=false;    
        this.num_rollings = $('.rolling_div').length;
        if (this.timer!==null) clearTimeout(this.timer);

        var i=1;

        SetOpacity(document.getElementById("rolling_img0"),100);
        if (this.num_rollings>1) {
            //Postload the rest of the banners after banner0
            for (i=1; i<this.num_rollings; i++) {
                //First, load it in and make it call an onload after loading. At the same time, create the img-tag with the link. 
                var objImage = new Image();
                objImage.onLoad=this.postload_onload(i);
                objImage.src=postload_array[i].src;

            }
        }

    }

    this.postload_onload = function(nr) {
        //nr = banner_nr som den har laddat
        //Skapa img-taggen
        var imgTag = document.createElement('img');
        imgTag.src = postload_array[nr].src;
        imgTag.id = "rolling_img"+nr;
        imgTag.className = "rolling_img";

        var aTag = document.createElement('a');
        aTag.setAttribute('href', postload_array[nr].href);
        aTag.appendChild(imgTag);

        divTag = document.getElementById("rolling_div"+nr);
        divTag.innerHTML='';
        divTag.appendChild(aTag);

        SetOpacity(document.getElementById("rolling_img"+nr),0);

        //Om detta är sista img-taggen, aktivera knapp-diven och kickstarta snurren
        if ( $('.rolling_div').length == $('.rolling_img').length) {
            document.getElementById('rolling_button_container').style.display='block';
            this.rolling_buttons_set_active(0);
            this.fade_direction=0;   //0=hang out for a while before we fade it out
            this.timer = window.setTimeout("Snurrbanner.rolling_handler()",this.between_fade_delay);
        }
    }


    this.ChangeOpacity = function(id,msDuration,msStart,fromO,toO)
    {
        var fading_up=false;
        if(toO>fromO) fading_up=true;
        //debug_print(fading_up);

      var element=document.getElementById(id);
      if (element===null) return;

      var msNow = (new Date()).getTime();
      opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
      if (opacity<0) {
        SetOpacity(element,0)
        this.rolling_handler(); //called when done
      } else if (opacity>100) {
        SetOpacity(element,100)
        this.rolling_handler(); //called when done
        } else if(fading_up==true && this.snurrbanner_is_mouseover==true && opacity>90) {
            SetOpacity(element,90)
            this.fade_direction=0;
            //rolling_handler(); //called when done
        }
      else
      {
        SetOpacity(element,opacity);
        element.timer = window.setTimeout("Snurrbanner.ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",25);
      }
    }

    this.FadeIn = function(id, speed)
    {
      var element=document.getElementById(id);
      if (element===null) return;
      if (element.timer) window.clearTimeout(element.timer); 
      var startMS = (new Date()).getTime();
      element.timer = window.setTimeout("Snurrbanner.ChangeOpacity('" + id + "',"+speed+"," + startMS + ",0,100)",1);
    }

    this.FadeOut = function(id, fromOpacity, speed)
    {
      var element=document.getElementById(id);
      if (element===null) return;
      if (element.timer) window.clearTimeout(element.timer); 
      var startMS = (new Date()).getTime();
      element.timer = window.setTimeout("Snurrbanner.ChangeOpacity('" + id + "',"+speed+"," + startMS + ","+fromOpacity+",0)",1);
    }

    this.quick_switch_to = function(nr) {
        if (nr==this.cur_rolling) return;

        //Kill all the timers
        window.clearTimeout(this.timer);
        for (var i=0; i<this.num_rollings; i++) {
            id="rolling_img"+i;
            var element=document.getElementById(id);
            if (element!==null)
                window.clearTimeout(element.timer);
        }

        //Quick fadeout cur_rolling
        var element=document.getElementById("rolling_img"+this.cur_rolling);
        if (element!==null) {
            var opacity = element.style.opacity * 100;
            this.fade_direction=-1;
            this.next_rolling=nr;
            this.FadeOut("rolling_img"+this.cur_rolling, opacity, 50);
        }
    }

    this.rolling_handler = function() {
        //alert('Snurrbanner.rolling_handler(). this.fade_direction='+this.fade_direction);
        if (this.fade_direction==-1) {
            //fadeout done. Kill the current div, change div/img, kickstart it and fade it in.
            var speed=1000; //default speed
            var element=document.getElementById("rolling_div"+this.cur_rolling);
            if (element===null) return;

            element.style.display="none";
            if (this.next_rolling!==false) {  //Override when a click has been done on the buttons
                this.cur_rolling=this.next_rolling;
                this.next_rolling=false;
                var speed=400;
            } else {
                this.cur_rolling++;
                if (this.cur_rolling==this.num_rollings) this.cur_rolling=0;
            }

            element=document.getElementById("rolling_div"+this.cur_rolling);
            if (element===null) return;
            element.style.display="block";
            this.fade_direction=1;
//debug_print("fadein: rolling_img"+this.cur_rolling);
            this.rolling_buttons_set_active(this.cur_rolling);
            this.FadeIn("rolling_img"+this.cur_rolling, speed);
        }
        else if(this.fade_direction==1){
            //fadein done. Hang out. Relax for a while.
//debug_print("relaxing..: rolling_img"+this.cur_rolling);
            this.fade_direction=0;   //hang out for a while before we fade it out
            this.timer = window.setTimeout("Snurrbanner.rolling_handler()",this.between_fade_delay);
            
        } else {
            //Now it is time to fade out.
            this.fade_direction=-1;
//debug_print("fadeout.: rolling_img"+this.cur_rolling);
            var element=document.getElementById("rolling_img"+this.cur_rolling);
            if (element===null) return;

            var opacity = element.style.opacity * 100;
            this.FadeOut("rolling_img"+this.cur_rolling, opacity, 1000);
        }
    }

    this.rolling_buttons_set_active = function(nr) {
        if (this.on_button_mouseover==true) return;

        for (i=0; i<this.num_rollings; i++) {
            var button_normal=document.getElementById("rolling_button_"+i+"_normal");
            var button_onmouseover=document.getElementById("rolling_button_"+i+"_onmouseover");
            if (button_normal===null || button_onmouseover===null) return;

            if (i==nr) {
                button_normal.style.display='none';
                button_onmouseover.style.display='block';
                // highlight it
            } else {
                // clear it
                button_normal.style.display='block';
                button_onmouseover.style.display='none';
            }
        }
    }


    this.snurrbanner_onmouseover = function() {
        this.snurrbanner_is_mouseover=true;
    //    alert("mouseOVER");
        if (this.fade_direction==0) {
            window.clearTimeout(this.timer);
            var element=document.getElementById("rolling_img"+this.cur_rolling);
            if (element!==null) 
                SetOpacity_no_ie(element,90);
        }
    /*
        //Stop all the timers
        window.clearTimeout(timer);
        for (i=0; i<num_rollings; i++) {
            id="rolling_img"+i;
            var element=document.getElementById(id);
            if (element!==null) {
                window.clearTimeout(element.timer);
                if (i==cur_rolling)
                    SetOpacity(element,90);
            }
        }
    */
    }

    this.snurrbanner_onmouseout = function() {
        this.snurrbanner_is_mouseover=false;
    //    alert("mouseOUT");
        if (this.fade_direction==0) {
            window.clearTimeout(this.timer);
            this.timer = window.setTimeout("Snurrbanner.rolling_handler()",2000);
            var element=document.getElementById("rolling_img"+this.cur_rolling);
            if (element!==null) 
                SetOpacity(element,100);
        }
    }

});   //new Snurrbanner

     function SetOpacity(element,opacity)
    {
      //element.style.MozOpacity = opacity/100; //For mozilla based browsers. Obsolete since firefox 0.9 (or mozilla 0.9. Old anyway)
      if (element===null) return;
      element.style.filter = 'alpha(opacity=' + opacity + ')';    //..microsoft dito
      element.style.opacity = opacity/100;    //css3?
    }

    function SetOpacity_no_ie(element,opacity)
    {
      if (element===null) return;
      //element.style.MozOpacity = opacity/100; //For mozilla based browsers. Obsolete since firefox 0.9 (or mozilla 0.9. Old anyway)
    /*  element.style.filter = 'alpha(opacity=' + opacity + ')';    //..microsoft dito */
      element.style.opacity = opacity/100;    //css3?
    }



     function product_box_onmouseover(id) {
        var element=document.getElementById("products_box_top_"+id);
        if (element!==null) SetOpacity_no_ie(element, 85);        
        var element=document.getElementById("products_box_middle_"+id);
        if (element!==null) SetOpacity_no_ie(element, 85);        
        var element=document.getElementById("products_box_bottom_"+id);
        if (element!==null) SetOpacity_no_ie(element, 85);        
    }


    function product_box_onmouseout(id) {
        var element=document.getElementById("products_box_top_"+id);
        if (element!==null) SetOpacity_no_ie(element, 100);        
        var element=document.getElementById("products_box_middle_"+id);
        if (element!==null) SetOpacity_no_ie(element, 100);        
        var element=document.getElementById("products_box_bottom_"+id);
        if (element!==null) SetOpacity_no_ie(element, 100);        
    }


var svekost_debug_text='';
var js_debug_id=0;
function debug_print(text) {
    var ruta = document.getElementById("js_debugruta");
    if (ruta===null) svekost_debug_text += "<br>js_id:" + js_debug_id + ": " +text;    //buffer it for later printing when id=js_debugruta exists
    else
        ruta.innerHTML = ruta.innerHTML + "<br>js_id:" + js_debug_id + ": " +text;    

    js_debug_id++;
}

Megameny = new (function() {

    this.init = function() {

        $("#megameny").hoverIntent({sensitivity:3,interval:50,over:this.showbody,timeout:400,out:this.hidebody});

        $("#megameny_toolbar .node").mouseenter(function() {
            var index = $("#megameny_toolbar .node").index(this);   //First get the right indexY-class

            /* if (jQuery.support.opacity)
                $(this).find('.cursor_bg').stop(false,true).fadeIn(500);
            else    */ 
                $(this).find('.cursor_bg').show();

            //Remove hov on every node but this one
            $("#megameny_toolbar .node").not('.index'+index).find('.text').stop(false,true).removeClass("hov", 200);

            //Add hov on this node
            $(this).find('.text').stop(false, true).addClass("hov", 200);
            $("#megameny_toolbar .node").not('.index'+index).find('.bg').addClass('closed').removeClass('open');
            $(this).find('.bg').addClass('open').removeClass('closed');



            //if this menu-content is already showing, then no need to do anything
            if ( $('#megameny-body .menu-content.index'+index).is(':hidden') ) {
                //var columns = $('#megameny-body .menu-content.index'+index+' .slide-content li.column').length;

                //Rewind everyone except this one (before they are hidden ... otherwise the rewind does not work).
                $('#megameny-body .menu-content').not('.index'+index).find('.slide-content.scrollable').scrollTo('0px');
                $('#megameny-body .menu-content').not('.index'+index).find('.slide-content.scrollable').trigger( 'goto', [ 0 ] );    //Reset the position

                //Hide all content except this one
                $('#megameny-body .menu-content').not('.index'+index).hide();   
                //..and show the correct one.
                $('#megameny-body .menu-content.index'+index).show();



                //$('#content').html($('#content').html() + '<br>#megameny-body .menu-content.index'+index);
/*
                var items_to_exclude = 3;
                var num_columns_visible = 4;
                if (  $('#megameny-body .menu-content.index'+index).hasClass('type3')) { items_to_exclude=4; num_columns_visible=5; }

                if (columns>=num_columns_visible) {
                    $('#megameny-body .menu-content.index'+index).serialScroll({
                            target:'div.slide-content',
                            items:'li.column',
                            prev:'.slide-left',
                            next:'.slide-right',
                            offset:-8, //when scrolling to photo, stop 230 before reaching it (from the left)  -7
                            start:0, //as we are centering it, start at the 2nd
                            duration:800,
                            force:false,
                            step:1,
                            stop:true,
                            lock:false,
                            cycle:false, //don't pull back once you reach the end
                            easing:'easeOutQuart', //use this easing equation for a funny effect
                            jump: false, //click on the images to scroll to them
                            exclude: items_to_exclude,
                            onBefore:function( e, elem, $pane, $items, pos ){
                                var num_columns = $($pane).find('li.column').length;

                                //Start by showing both.
                                var o;
                                if (pos!=(num_columns-items_to_exclude-1)) {
                                    o = $($pane).parent().find('.slide-right').css("opacity");
                                    if (o==0) $($pane).parent().find('.slide-right').css("visibility","visible").fadeTo(500,1);
                                }
                                
                                if (pos!=0) {
                                    o = $($pane).parent().find('.slide-left').css("opacity");
                                    if (o==0) $($pane).parent().find('.slide-left').css("visibility","visible").fadeTo(500,1);
                                }
                                //If we hit the right most place, then hide the right arrow
                                if (num_columns-items_to_exclude-1 == pos) {
                                    //$($pane).parent().find('.slide-right').css("visibility","hidden");
                                    $($pane).parent().find('.slide-right').fadeTo(500, 0, function() { $(this).css("visibility","hidden"); } );
                                }

                                //If we hit the left most place, then hide the left arrow
                                if (pos==0) {
                                    //$($pane).parent().find('.slide-left').css("visibility","hidden");
                                    $($pane).parent().find('.slide-left').fadeTo(500, 0, function() { $(this).css("visibility","hidden"); } );
                                } 
                            },
                            onAfter:function() {
                            }
                    });

                   //Hide the left slider and show the right
                    $('#megameny-body .menu-content.index'+index).find('.slide-left').fadeTo(0, 0, function() { $(this).css("visibility","hidden"); } );
                    $('#megameny-body .menu-content.index'+index).find('.slide-right').css("visibility","visible").fadeTo(0,1);
                }
*/


            }


        


       });

        $("#megameny_toolbar .node").mouseleave(function() {
            var index = $("#megameny_toolbar .node").index(this);   //First get the right indexY-class

            /*if (jQuery.support.opacity)
                $(this).find('.cursor_bg').stop(false,true).fadeOut(300);
            else */
                $(this).find('.cursor_bg').hide();

            //if megameny-body is closed, then remove the hov class

            if ( $('#megameny-body').is(':hidden') ) {
                $(this).find('.text').stop(false,true).removeClass("hov", 200);
                $(this).find('.bg').removeClass('open').addClass('closed');
            }

            //$('#megameny-body .menu-content.index'+index).find('.slide-content').scrollTo('0px');


       });





        $("#megameny_toolbar .node").mousemove(function(e){
/*            var x = e.pageX - this.offsetLeft;
            var x = this.offsetLeft;
	        var y = e.pageY - this.offsetTop;
	        var y = this.offsetTop;

            var offset = $(this).offset();
            var position = $(this).position();

            var mytxt = this.tagName + " coords ( " + offset.left + ", " +
                                  offset.top + " )";
            mytxt = mytxt + this.tagName + " pos ( " + position.left + ", " +
                                  position.top + " )";
            $('#content').text(mytxt);
*/

//            $(this).parent().find('.node .cursor_bg').hide();

            var offset = $(this).offset();
            var x = e.pageX - offset.left - 75;
	        //var y = e.pageY - offset.top - 75;

            //Due to the way the last menu is done, we cant allow the background to go all the way to the right. It would show outside the menu and look bad.
            //Remember IE<9 has very poor opacity capability. Cant fade it.
            if ($(this).hasClass( 'last')) { 
                var width = $(this).find('.bg').width();
                var op=1;
/*
                if (x>0) {
                    op = (100-(3*x))/100;
                    if (op<0) op=0;
                    if (op>1) op=1;
                }                
*/
                var diff = (width-(e.pageX-offset.left));
                if (diff<50) {
                    op = diff/50;
                    if (op<0) op=0;
                    if (op>1) op=1;
                }                

                if (jQuery.support.opacity) {
                    $(this).find('.cursor_bg').css({ opacity: op });
                } else {
/*                    if (op<1) $(this).find('.cursor_bg').hide();
                    else $(this).find('.cursor_bg').show(); */
                }
            }

            $(this).find('.cursor_bg').css('left', x);//.css('top', y);
        }); 



        $("#megameny-body .menu-content .slide-right").hoverIntent({sensitivity:3,interval:50,over:this.slide_right_start,timeout:3,out:this.slide_right_stop});
        $("#megameny-body .menu-content .slide-left").hoverIntent({sensitivity:3,interval:50,over:this.slide_left_start,timeout:3,out:this.slide_left_stop});
        

        // Easing equation, borrowed from jQuery easing plugin
        // http://gsgd.co.uk/sandbox/jquery/easing/

        jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
            return -c * ((t=t/d-1)*t*t*t - 1) + b;
        };

        jQuery.easing.easeOutBounce = function (x, t, b, c, d) {
		    if ((t/=d) < (1/2.75)) {
			    return c*(7.5625*t*t) + b;
		    } else if (t < (2/2.75)) {
			    return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		    } else if (t < (2.5/2.75)) {
			    return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		    } else {
			    return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		    }
    	};


        $('#megameny-body .menu-content').each(function(index) {
            var items_to_exclude = 3;
            if (  $(this).hasClass('type3')) { items_to_exclude=4; }

            if ($(this).find('.slide-content').hasClass('scrollable')) {
                $(this).serialScroll({
                        target:'div.slide-content',
                        items:'li.column',
                        prev:'.slide-left',
                        next:'.slide-right',
                        offset:-8, //when scrolling to photo, stop 230 before reaching it (from the left)  -7
                        start:0, //as we are centering it, start at the 2nd
                        duration:800,
                        force:false,
                        step:1,
                        stop:true,
                        lock:false,
                        cycle:false, //don't pull back once you reach the end
                        easing:'easeOutQuart', //use this easing equation for a funny effect
                        jump: false, //click on the images to scroll to them
                        exclude: items_to_exclude,
                        onBefore:function( e, elem, $pane, $items, pos ){
                            var num_columns = $($pane).find('li.column').length;

                            //Start by showing both.
                            var o;
                            if (pos!=(num_columns-items_to_exclude-1)) {
                                o = $($pane).parent().find('.slide-right').css("opacity");
                                if (o==0) $($pane).parent().find('.slide-right').css("visibility","visible").fadeTo(500,1);
                            }
                            
                            if (pos!=0) {
                                o = $($pane).parent().find('.slide-left').css("opacity");
                                if (o==0) $($pane).parent().find('.slide-left').css("visibility","visible").fadeTo(500,1);
                            }
                            //If we hit the right most place, then hide the right arrow
                            if (num_columns-items_to_exclude-1 == pos) {
                                //$($pane).parent().find('.slide-right').css("visibility","hidden");
                                $($pane).parent().find('.slide-right').fadeTo(500, 0, function() { $(this).css("visibility","hidden"); } );
                            }

                            //If we hit the left most place, then hide the left arrow
                            if (pos==0) {
                                //$($pane).parent().find('.slide-left').css("visibility","hidden");
                                $($pane).parent().find('.slide-left').fadeTo(500, 0, function() { $(this).css("visibility","hidden"); } );
                            } 
                        },
                        onAfter:function() {
                        }
                });






            }


        });


/*
        $('#megameny-body .menu-content').serialScroll({
                target:'div.slide-content',
                items:'li.column',
                prev:'.slide-left',
                next:'.slide-right',
                offset:0, //when scrolling to photo, stop 230 before reaching it (from the left)
                start:0, //as we are centering it, start at the 2nd
                duration:800,
                force:true,
                step:1,
                stop:true,
                lock:false,
                cycle:false, //don't pull back once you reach the end
                easing:'easeOutQuart', //use this easing equation for a funny effect
                jump: false, //click on the images to scroll to them
                exclude: 3,
                onBefore:function( e, elem, $pane, $items, pos ){
                    var num_columns = $($pane).find('li.column').length;

                    //Start by showing both.
                    var o;
                    if (pos!=(num_columns-3-1)) {
                        o = $($pane).parent().find('.slide-right').css("opacity");
                        if (o==0) $($pane).parent().find('.slide-right').css("visibility","visible").fadeTo(500,1);
                    }
                    
                    if (pos!=0) {
                        o = $($pane).parent().find('.slide-left').css("opacity");
                        if (o==0) $($pane).parent().find('.slide-left').css("visibility","visible").fadeTo(500,1);
                    }
                    //If we hit the right most place, then hide the right arrow
                    if (num_columns-3-1 == pos) {
                        //$($pane).parent().find('.slide-right').css("visibility","hidden");
                        $($pane).parent().find('.slide-right').fadeTo(500, 0, function() { $(this).css("visibility","hidden"); } );
                    }

                    //If we hit the left most place, then hide the left arrow
                    if (pos==0) {
                        //$($pane).parent().find('.slide-left').css("visibility","hidden");
                        $($pane).parent().find('.slide-left').fadeTo(500, 0, function() { $(this).css("visibility","hidden"); } );
                    } 
                },
                onAfter:function() {
                }
        });
*/ 

   }   //init()


    this.slide_right_start = function() { 
        $(this).parent().find('.slide-content').trigger('next');
        $(this).parent().find('.slide-content').everyTime(600, function() { 
            $(this).trigger('next');
        });
    }
    
    this.slide_right_stop = function() { $(this).parent().find('.slide-content').stopTime(); }


    this.slide_left_start = function() { 
        $(this).parent().find('.slide-content').trigger('prev');
        $(this).parent().find('.slide-content').everyTime(600, function() { 
            $(this).trigger('prev');
        });
    }
    
    this.slide_left_stop = function() { $(this).parent().find('.slide-content').stopTime(); }

    this.showbody = function() { 
        $('#megameny-body').fadeIn(250); 
/*
        //Rewind everyone 
        $('#megameny-body .menu-content').find('.slide-content').scrollTo('0px');
        $('#megameny-body .menu-content').find('.slide-content').trigger( 'goto', [ 0 ] );    //Reset the position
*/

        $('#megameny_toolbar .node:first-child .bg').removeClass('closed').addClass('closed-straight');
        $('#header .right-lower-corner').show();
    }
    this.hidebody = function() { 
        //$('#megameny-body .slide-content').trigger( 'goto', [ 0 ] );  

        //Rewind everyone 
        $('#megameny-body .menu-content').find('.slide-content.scrollable').scrollTo('0px');
        $('#megameny-body .menu-content').find('.slide-content.scrollable').trigger( 'goto', [ 0 ] );    //Reset the position


        $('#megameny-body .menu-content').hide();
        $('#megameny-body').hide();  
        $('#megameny_toolbar .node:first-child .bg').removeClass('closed-straight').addClass('closed');
        $('#megameny_toolbar .node .bg').removeClass('open').addClass('closed');
        $('#header .right-lower-corner').hide();

        //Remove hov on every node
        $("#megameny_toolbar .node").find('.text').stop(false,true).removeClass("hov", 200);

    }
/*
    this.showbody2 = function() { $('#megameny-body').hide(); }
    this.hidebody2 = function() {  }
*/

});

/*
function simple_tooltip(target_items){
 $(target_items).each(function(i){
        var xOffset = 10;
        var yOffset = 20;

        if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){
            $(this).hover(function(e) {
                this.t = this.title;
                this.title="";
                $("body").append("<p id='tooltip'>"+ this.t +"</p>");
		        $("#tooltip")
			        .css("top",(e.pageY - xOffset) + "px")
			        .css("left",(e.pageX + yOffset) + "px")
			        .fadeIn("fast");	
            },
            function(){
		        this.title = this.t;
        		$("#tooltip").remove();
            });

            $(this).mousemove(function(e){
		        $("#tooltip")
			        .css("top",(e.pageY - xOffset) + "px")
			        .css("left",(e.pageX + yOffset) + "px");
            });
        }
	});
}
*/

//New version with hoverintent...
function simple_tooltip(target_items){
 $(target_items).each(function(i){
        var xOffset = 10;
        var yOffset = 20;


        this.tooltip_enter = function(e) {
            $("body").append("<p id='tooltip'>"+ $(this).attr('tooltip_title') +"</p>");
	        $("#tooltip")
		        .css("top",(e.pageY - xOffset) + "px")
		        .css("left",(e.pageX + yOffset) + "px")
		        .fadeIn("fast");	
        }
    
        this.tooltip_leave = function(e) {
        		$("#tooltip").remove();
         }

        if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){
            //first change the attribute "title" to "tooltip_title" so that we dont get our regular browser-built-in tooltip when hovering
            $(this).attr({ tooltip_title : $(this).attr('title') }).removeAttr('title');
            
            $(this).hoverIntent({sensitivity:3,interval:50,over:this.tooltip_enter,timeout:0,out:this.tooltip_leave});

            $(this).mousemove(function(e){
		        $("#tooltip")
			        .css("top",(e.pageY - xOffset) + "px")
			        .css("left",(e.pageX + yOffset) + "px");
            });
        }



	});
}



