function alertObject(obj,comment) {
  var str = (comment)? comment+"\n":'{';
  for(var el in obj) {
    var value = obj[el];
    if ( typeof value == "function" ) {
      value = "[<FUNCTION>]";
    }
    str += el + " : "+ value +" , ";
  }
  str +=" }"
  alert(str);
}

$(document).ready(function() {
  if ($('form').length > 0) {
    $('form').submit(function() {
      if (window.tinyMCE) {
        tinyMCE.triggerSave();
      }
      $(this).find(':text, :password, textarea').each(function() {
        $(this).val($.trim($(this).val()));   
      })  
    });
  }  
  $('form.validate').each(function() {
  	$(this).validate({
      errorElement: 'span'
    });  
  })
  
  $('table.tableHover tbody').find('tr').hover(function() {
  	$(this).css('background', '#e8e8e8')
  }, function() {
  	$(this).css('background', 'transparent')  	
  })
  
  $('table.tableHover tbody').find('tr').hover(function() {
    $(this).css('background', '#e8e8e8')
  }, function() {
    $(this).css('background', 'transparent')    
  })
  
  if ($("a.gallery").length > 0) {
  	$("a.gallery").overlay({ 
      target: '#gallery',  
      expose: '#f1f1f1',
      top: '5%',
      gallery: true  
    }).gallery({  
      speed: 800,      
      info: false
    });
  }
  
  if ($("a.enlargeLink").filter(':not(.gallery)').length > 0) {
  	$("a.enlargeLink").filter(':not(.gallery)').click(function(e) {
  		e.stopPropagation();  	
  	}).each(function() {
  		$(this).overlay({ 
        target: '#gallery',  
        expose: '#f1f1f1',
        top: '5%',
        gallery: true  
      }).gallery({  
        speed: 800,      
        info: false,
        single: true
      });  	
  	});
  }
});	/**
	* Checkboxes Util.
	* Insert input type"hidden" value"N" for all unchecked boxes.<b> 
	* Leaves check ones with the same value. Shloud be "Y".<b>
	* @author Alexei Chizhmakov (Itirra - http://itirra.com) 
	*/
	jQuery(document).ready(function () {
	  //Make input type hidden for all unchecked ckeckboxes
	  jQuery('input[type=checkbox]').filter(':not(:checked)').filter(':not(.exclude)').each(function callback() {
	  	 if (!jQuery(this).hasClass('validate')) {
	       jQuery(this).before(getInputHidden(jQuery(this).attr("name"), "N"));
	  	 }
	  });
	  //Bind click to all checkboxes	  
	  
	  jQuery("input[type=checkbox][class!=exclude]:not(.exclude)").live("click", function(event, isPreventdefault) {
	  		  	
	  	if (!jQuery(this).hasClass('validate')) {
  	    if (jQuery(this).is(":checked")) {
  	      jQuery('input[type=hidden][name=' + jQuery(this).attr("name") + ']').remove() ;
  	    } else {
  	      jQuery(this).before(getInputHidden(jQuery(this).attr("name"), "N"));	      
  	    }
	  	}
	  	if (isPreventdefault) {
	  		event.preventDefault();
	  	}
	  });	  
	  
	  /** Get input type hidden HTML. */
    function getInputHidden(name, value) {
      return '<input type="hidden" name="' + name + '" value="' + value + '" />';
    }	  
	});
	
$(document).ready(function() {
	
  if ($("#wizard").length > 0) {  	
    var root = $("#wizard").scrollable({size: 1, clickable: false, globalNav: true, prev: 'li.prev', next: 'li.next'});
    var api = root.scrollable();
    api.onBeforeSeek(function(event, i) {
      var items = $(".navigator li.item"),
          length = items.length,
          nextText = $(".navigator span.nextText"),
          prevText = $(".navigator span.prevText"),
          outerLink = $("#outerLink"),
          submitFormLink = $("#submitFormLink"),
          currElem = items.eq(i);
      items.removeClass("selected");
      currElem.addClass("selected");
      
      if (i - 1 > -1) {
        prevText.find('b').html(items.eq(i - 1).find('span').html());
      }
      if (i + 1 != length) {        
        nextText.find('b').html(items.eq(i + 1).find('span').html());
      }
      
      if (i == 0) {
        prevText.hide();
        outerLink.css('display', 'block');
        nextText.css('display', 'block');
        submitFormLink.hide();
      }
      
      if (i > 0 && i < length) {
        outerLink.hide();
        submitFormLink.hide();
        prevText.css('display', 'block');
        nextText.css('display', 'block');                      
      }     

      if (i == length - 1) {
        nextText.hide();
        submitFormLink.css('display', 'block');       
      }     
    });
    
    api.onSeek(function(event, i) {
    	var maxPageHeight = 453;      
      var currPageHieght = $('#wizard .items div.page').eq(i).height();
      
      setTimeout(function() {
      	if (currPageHieght > maxPageHeight) {
          $('#wizard').animate({'height': currPageHieght},500);       
        } else {
          $('#wizard').animate({'height': maxPageHeight},500);
        }
      }, 100);     
      
    });
    
    function updateCurrPrice() {
    	var newPrice;      	
    	if (window.currprices) {
    		newPrice = 0;
    		for (var key in currprices) {
    			newPrice += currprices[key];
    		}
    		$('#current_amount').val(newPrice);
    	}      	      	
    }
  
    function initWizard() {
    	var nextText = $(".navigator span.nextText"),
        prevText = $(".navigator span.prevText");
    
      var length = $(".navigator li.item").length;
      
      if (length == 1) {
        nextText.hide();
        prevText.hide();
        $("#outerLink").css('display', 'block');
        $("#submitFormLink").css('display', 'block')
      } else {
      	nextText.css('display', 'block');
        nextText.find('b').html($(".navigator li.item").eq(1).find('span').html());
      }
      updateCurrPrice();
      
    }    
    initWizard();
    var validator;  
    if (jQuery("#createItemForm").length == 1) {      
      validator = jQuery("#createItemForm").validate({
      	errorElement: 'span',
      	rules: (window.rules) ? rules : {},
        submitHandler: function(form) {
        	var result = true;
        	var scrolledElement = null;
        	if (jQuery('input.shape').length > 0) {    
            var shapeOptions = jQuery('input.shape');
            for (var i = 0; i < shapeOptions.length; i++) {
              if (!shapeOptions[i].value) {
              	if (!scrolledElement) {              		
              	  scrolledElement = $(shapeOptions[i]).parent().find('.selectImageUl');
              	}              	
              	if ($(shapeOptions[i]).next().hasClass('error')) {
                        $(shapeOptions[i]).next().find('.error').remove();
              		$(shapeOptions[i]).next().remove();                  
              	}
              	$(shapeOptions[i]).after('<div class="error"><span class="error">Please select an option</span></div>');                
                result = false;
              }
            }
          }          
          if (!result) {
          	$.scrollTo(scrolledElement[0], 300, {offset:-50, axis: 'y'});          	 
          } else {
            EJEJC_tlc(form);
          }
        }
      });      
      
      validator.focusInvalid = function() {
        if( this.settings.focusInvalid ) {        
          try {
            var focused = jQuery(this.findLastActive() || this.errorList.length && this.errorList[0].element || []);//.filter(":visible");
            if (!focused.is(':hidden')) {
            	$.scrollTo(focused, 300, {offset:-50, axis: 'y'});              
            } else {                 	
            	$.scrollTo(focused.parent(), 300, {offset:-50, axis: 'y'});              
            }
          } catch(e) {
            // ignore IE throwing errors when focusing hidden elements
          }
        }
      };
    }
     
    if ($('ul.selectImageUl').length > 0) {
      $('ul.selectImageUl').find('li').click(function() {        	
        var currIndex = $(this).parent().find('li').index(this);
        var oID = $(this).find('input[type=hidden]').val()
        $(this).parent().find('li').removeClass('selected').eq(currIndex).addClass('selected'); 
        $(this).parents('.optionsBlock').find('input[type=hidden]:first').val(oID);          
        if ($(this).parent().hasClass('featureOptions')) {
        	var fId = $(this).parents('.optionsBlock:first').find('input.feature').attr('name');          	
        	currprices[fId] = featuresConfig[fId][oID];
        	updateCurrPrice();          	
        }
      })  
    }
  } 
});
