$(document).ready(function (){

    var tabs = $(".tabs.jquery");
		if (tabs) {
			tabs.tabs();
		}

/*    var select = $("select")
		if (select) {
			select.each(function(){
	
	        var select = $(this);
	
	        var html = $('<div class="js-select" id="'+select.attr('id')+'-replacement" original="'+select.attr('id')+'" opened="false"><span class="left"></span><ul></ul><span class="right"></span></div>');
	
	        var jsSelect = $("ul",html);
	
	        $("option",select).each(function(){
	
	            var opt = $(this);
	            var newLi = $('<li optionval="'+opt.val()+'" class="'+opt.attr('class')+'">'+opt.attr('text')+'</li>');
	
	            jsSelect.append(newLi);
	        });
	
	        var selectedIndex = $('option',select).index($('option:selected',select));
	
	        $('li',html).eq(selectedIndex).addClass('selected');
	
	        select.after(html);
	
	        var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	
	        if (!isIE6)
	        {
	
	            var max = 0;
	
	            $('li',html).each(function(){
	                var w = $(this).width()+parseInt($(this).css('padding-left'));
	
	                if (w > max) max = w;
	
	            });
	
	
	
	        }else
	        {
	            var max = select.width()+parseInt(select.css('padding-left'));
	        }
	
	        $('ul',html).css('width',(max+16)+'px');
	
	        if (!isIE6)
	        {
	            $('span.right',html).css('margin-left',(max+16)+'px');
	
	        }else
	        {
	            $('span.right',html).css('margin-left',((max/2)+12)+'px');
	        }
	
	        select.hide();
	
	    });
		}

    $(".js-select li").live('click',function(){
        var opt = $(this);
        var ul  = opt.parent();
        var select = $("#"+ul.parent().attr('original'));

        var originalOption = $("option",select).eq($("li",ul).index(opt));

        $("li", select).removeAttr('selected');

        originalOption.attr('selected','selected');
        $("li",ul).removeClass("selected");
        opt.addClass('selected');

        ul.parent().attr('opened','false');
        ul.parent().removeClass('opened');
        $('li:not(.selected)',ul).hide();
    });

    $('.js-select span.right').live('click',function(){

        if ($(this).parent().attr('opened') == 'false')
        {
            $('li',$(this).parent()).show();
            $(this).parent().attr('opened','true');
            $(this).parent().addClass('opened');
        }else
        {
            $('li:not(.selected)',$(this).parent()).hide();
            $(this).parent().attr('opened','false');
            $(this).parent().removeClass('opened');
        }
        
    });
*/
    var checkboxes = $("input[type=checkbox]")
    
    if (checkboxes) {
	    checkboxes.each(function(){
	        var cb = $(this);
	
	        var html = $('<span class="checkbox '+cb.attr('class')+'" original="'+cb.attr('id')+'" id="'+cb.attr('id')+'-replacement">&nbsp;</span>');
	        
	        if (cb.attr('checked'))
	        {
	            html.addClass('checked','checked');
	        }
	
	        cb.after(html);
	        cb.hide();
	    });
    }

    var checkbox = $('span.checkbox');
    
    if (checkbox) {
    	checkbox.live('click',function(){
	        var cb = $(this);
	        
	        if (cb.hasClass('checked'))
	        {
	            $("#"+cb.attr('original')).attr('checked', false);
	        } else {
	            $("#"+cb.attr('original')).attr('checked', true);
	        }
	
	        cb.toggleClass('checked');
	
	        return false;
	
	    });
    }

});

/* HOMEPAGE SLIDER GALLERY */
jQuery(document).ready(function(){
  jQuery("#left-arrow").mousehold(function() {
      movePhotos(203);
  });

  jQuery("#right-arrow").mousehold(function() {
      movePhotos(-203);
  });  
  
  
  //moves gallery according to the received parameter
  function movePhotos(move) {
     var left = parseInt(jQuery("#slider-wrapper ul").css("left").replace("px",""));
     left = left + move;
     
     var countPhotos = $('#slider-wrapper ul').children().size();
     if(left> 0 || left<-((countPhotos-4)*203)) {
          return;
     } else {
          left = left + "px";
          jQuery("#slider-wrapper ul").css("left",left);
     }
  }
});



/**
* jQuery mousehold plugin - fires an event while the mouse is clicked down.
* Additionally, the function, when executed, is passed a single
* argument representing the count of times the event has been fired during
* this session of the mouse hold.
*
* @author Remy Sharp (leftlogic.com)
* @date 2006-12-15
* @example $("img").mousehold(200, function(i){  })
* @desc Repeats firing the passed function while the mouse is clicked down
*
* @name mousehold
* @type jQuery
* @param Number timeout The frequency to repeat the event in milliseconds
* @param Function fn A function to execute
* @cat Plugin
*/

jQuery.fn.mousehold = function(timeout, f) {
      if (timeout && typeof timeout == 'function') {
              f = timeout;
              timeout = 100;
      }
      if (f && typeof f == 'function') {
              var timer = 0;
              var fireStep = 0;
              return this.each(function() {
                      jQuery(this).mousedown(function() {
                              fireStep = 1;
                              var ctr = 0;
                              var t = this;
                              timer = setInterval(function() {
                                      ctr++;
                                      f.call(t, ctr);
                                      fireStep = 2;
                              }, timeout);
                      })

                      clearMousehold = function() {
                              clearInterval(timer);
                              if (fireStep == 1) f.call(this, 1);
                              fireStep = 0;
                      }

                      jQuery(this).mouseout(clearMousehold);
                      jQuery(this).mouseup(clearMousehold);
              })
      }
}
