jQuery.noConflict();
var defaultText = {
	init : function() {
		jQuery(".defaultText").addClass("defaultTextActive");
		jQuery(".defaultText").focus(function() {
			if (jQuery(this).val() == jQuery(this)[0].title || jQuery(this).attr('id') == 'search') {
				jQuery(this).removeClass("defaultTextActive");
				jQuery(this).val("");
                        }

		});
		jQuery(".defaultText").blur(function() {
                        if (jQuery(this).val() == "") {
				jQuery(this).addClass("defaultTextActive");
				jQuery(this).val(jQuery(this)[0].title);
			}
			else if (jQuery(this).val() == jQuery(this)[0].title && jQuery(this).attr('id') == 'search') {
				jQuery(this).addClass("defaultTextActive");
			}
		});
		jQuery(".defaultText").blur();
	}
};
var inputVal = {
    init : function() {
        jQuery("input.input-text").focus(function() {
            if (this.id.match('postcode')) {
                jQuery(this).attr({
                    "maxlength":"5",
                    "minlength":"5"
                });
            }
            if (this.id.match('telephone')) {
                jQuery(this).attr({
                    "maxlength":"10",
                    "minlength":"7"
                });
            }
            if (this.id.match('firstname')) {
            	jQuery(this).attr({
            		"maxlength":"12"
            	});
            }
            if (this.id.match('lastname')) {
            	jQuery(this).attr({
            		"maxlength":"15"
            	});
            }
        });
    }
};
var linkProcessor = {
	init : function() {
		jQuery('a').click(function(){
			if(this.rel.match('external')) {
				var newWindow = window.open(this.href);
				newWindow.focus();
				return false;
			}
			if(this.rel.match('live-chat')) {
				this.target = 'VelaroChat';
				var newWindow = window.open(this.href, 'VelaroChat', 'toolbar=no, location=no, directories=no, menubar=no, status=no, scrollbars=no, resizable=yes, replace=no');
				newWindow.focus();
				newWindow.opener = window;
				return false;
			}
			if(jQuery(this).hasClass('show_reviews')) {
				tabGen.showReviews();
			}
		});
	}
};

var carousel = {
	init: function() {
		if(jQuery(".carousel")) {
                        carousel.getSize();
                        jQuery(".carousel .items").each(function(i) {
                           if (jQuery(this).children().length <= carousel.settings.size) {
                               jQuery(this).parent().parent().find(".prev, .next, .prevPage, .nextPage").hide();
                           }
                           i++;
                        });
			jQuery(".carousel").scrollable(this.settings).circular().mousewheel(13);
     
		}
	},

	settings : {
		activeClass: "active",
		api: null,
		clickable: false,
		disabledClass: "_no-display_",
		easing: "linear",
		hoverClass: null,
		item: null,
		items: ".items",
		keyboard: true,
		loop: false,
		nextPage: ".nextPage",
		next: ".next",
		prevPage: ".prevPage",
		prev: ".prev",
		speed: 400,
		vertical: false
	},
        getSize : function(){
            if (jQuery(".cart .carousel").length > 0){
                carousel.settings.size = 2;
                carousel.settings.keyboardSteps = 2;
            }else{
                carousel.settings.size = 5;
                carousel.settings.keyboardSteps = 5;
            }
        }

};
var tabGen = {
	init : function() {
		if(jQuery("ul.tabs")) {
			this.api = jQuery("ul.tabs").tabs("div.panes > div", {api:true});
		}
	},
	showReviews : function() {
		this.api.click('#reviews');
	}
};
jQuery(document).ready(function(){
	defaultText.init();
	linkProcessor.init();
	tabGen.init();
	carousel.init();
        inputVal.init();
});