﻿$.fn.equals = function(compareTo) {
  if (!compareTo || this.length != compareTo.length) {
    return false;
  }
  for (var i = 0; i < this.length; ++i) {
    if (this[i] !== compareTo[i]) {
      return false;
    }
  }
  return true;
};
function debug(x) {
    try {
        console.debug(x);
    } catch (e) {
        alert(x);
    }
}
// Form watermark
// Written by: David Stevens
///////////////////////////////////////
 (function ($) {
		var txtfield = [];
        var methods = {
            init: function (options) {
                var defaults = {
                    imageIndex: 0,
                    container: '.c_content',
                    padding: 10,
                    teaserWidth:219,
                    paddingTop:5,
                    label:null
                };
                var options = $.extend(defaults, options);
                return this.each(function () {
                    var obj = $(this);
                    var wrapper = $('<div id="fwatermark-wrapper" />').css({position:'relative'}).insertAfter(obj);
					obj.find('input[type=text],textarea').each(function(){
						var elm = $(this);
                        var bareelm = this;
						var label = (options.label)?elm.siblings(options.label):elm.siblings("label[for=" + this.id + "]");
                        if(label.length <= 0){
                            return;
                        }
						label.addClass('watermark_label').css({display:'block',position:'absolute',margin:'0 0 0 0',paddingTop:options.paddingTop,width:elm.innerWidth() - 20})
                            .click(function(){
                                elm.trigger('focus');
                                //methods.set_focus(bareelm);
                            });
						txtfield[this.id] = {input : elm, label : label};
					});		
					obj.appendTo(wrapper);
					for(key in txtfield){
						var obj = txtfield[key];
						methods.set_css(obj);
						obj.input.focus(function(){
							methods.set_focus(this);
						}).blur(function(){
							methods.set_blur(this);
						});
					}								
                });
            },
			set_css:function(obj){
				var label = obj.label;
				var input = obj.input;
				input.css({position:'relative'});
				label.css({
					zIndex:100,
					top:input.position().top,
					left:input.position().left + (input.css('paddingLeft').replace('px','') * 1 )
				});
				if(input.val().length > 0){
					label.hide();
				}
			},
			set_focus:function(input){
				var obj = txtfield[input.id];                
				obj.label.hide('fast');
			},
			set_blur:function(input){
				var obj = txtfield[input.id];
				if(obj.input.val().length <= 0){
					obj.label.show('fast');
				}
			}
        };
        $.fn.formwatermark = function (method) {
            // Method calling logic
            if (methods[method]) {
                return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
            } else if (typeof method === 'object' || !method) {
                return methods.init.apply(this, arguments);
            } else {
                $.error('Method ' + method + ' does not exist on jQuery.tooltip');
            }

        };
    })(jQuery);


// Checklist
///////////////////////////////////////
(function ($) {

    var methods = {
        init: function (options) {
            var defaults = {
                activestate:'active'
            };
            var options = $.extend(defaults, options);

            return this.each(function () {
                var input = $(this);
                var label = input.siblings('label');
                input.data('options',options);
                input.focus(function(){
                    label.addClass('checklist-hover');
                }).blur(function(){
                    label.removeClass('checklist-hover');
                }).change(function(){
                    label.toggleClass('checklist-active');
                    label.removeClass('checklist-hover');
                });
            });

        }
    };
    $.fn.surveychecklist = function (method) {
        // Method calling logic
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.tooltip');
        }

    };
})(jQuery);

// EQUAL HEIGHT
///////////////////////////////////////
(function ($) {

    var methods = {
        init: function (options) {
            var defaults = {
                activestate: 'active'
            };
            var options = $.extend(defaults, options);
            var obj = this;
            var maxheight = 0;

            this.each(function () {
                var elm = $(this);
                maxheight = (elm.height() > maxheight) ? elm.height() : maxheight;
            });

            return this.each(function () {
                var elm = $(this);
                elm.height(maxheight);
            });

        }
    };
    $.fn.equalheight = function (method) {
        // Method calling logic
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.tooltip');
        }

    };
})(jQuery);

// ACCORDIAN
///////////////////////////////////////
(function ($) {

    var methods = {
        init: function (options) {
            var defaults = {
                activestate:'active',
                handle:'.handle',
                content:'.a_content'
            };
            var options = $.extend(defaults, options);
            
            return this.each(function () {
                var obj = $(this);     
                obj.data('options',options);
                var handle = $(options.handle, obj);                
                var content = $(options.content, obj);
                var oheight = content.outerHeight();
                var wrapper = $('<div class="a_wrapper" />').insertAfter(content).append(content).slideUp(0);
                var parent = wrapper.parent().parent();
                $("<div class='handle-image'/>").prependTo(handle).toggle(function(){
                    wrapper.slideDown(600,'easeInExpo');
                    parent.animate({height:parent.height() + oheight},600,'easeInExpo');
                },function(){
                    wrapper.slideUp(500,'easeOutSine');
                    parent.animate({height:parent.height() - oheight},500,'easeOutSine');
                });
            });

        }
    };
    $.fn.accordian = function (method) {
        // Method calling logic
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.tooltip');
        }

    };
})(jQuery);

// ALT
///////////////////////////////////////
(function ($) {

    var methods = {
        init: function (options) {
            var defaults = {
                classname:'alt',
                selector:'tr'
            };
            var options = $.extend(defaults, options);
            
            return this.each(function () {
                var obj = $(this);     
                obj.data('options',options);                
                obj.find(options.selector).each(function(i){
                    if(i % 2 == 0){
                        $(this).addClass(options.classname);
                    }
                });
            });

        }
    };
    $.fn.alt = function (method) {
        // Method calling logic
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.tooltip');
        }

    };
})(jQuery);
