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();
                        //alert("carousel.getSize: " + carousel.settings.size);
                        jQuery(".carousel .items").each(function() {
                            //alert('each: ' + this);
                           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);
            //jQuery(".chooseBlockStep1b, #hot_deals, #best_sellers, #new_arrivals").each(function() {

            //	this.scrollable(carousel.settings);
            //});
        }
    },

    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 if (jQuery('.liners-index-index .carousel').length > 0) {
                carousel.settings.size = 7;
                carousel.settings.keyboardSteps = 7;
            } 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');
    }
};

var bannerSlider = {
	init : function() {
		if (jQuery('#banner_slider')) {
			jQuery('#banner_slider .playpause .butPlay').click(function(e) {
				jQuery("#banner_slider .slidetabs").data("slideshow").play();
				jQuery(this).hide();
				jQuery(this).next().show();
				e.preventDefault();
			});
			jQuery('#banner_slider .playpause .butPause').click(function(e) {
				jQuery(".slidetabs").data("slideshow").stop();
				jQuery(this).hide();
				jQuery(this).prev().show();
				e.preventDefault();
			});
			jQuery("#banner_slider .slidetabs").tabs("#banner_slider .images > div", {
				// enable "cross-fading" effect
				effect: 'fade',
				fadeOutSpeed: "slow",
				// start from the beginning after the last tab
				rotate: true
			}).slideshow({autoplay: true, interval: 5000});
		}
	}
};


jQuery(document).ready(function(){
    defaultText.init();
    linkProcessor.init();
    if (jQuery('body.cms-home').length == 0) {
        tabGen.init();
        carousel.init();
    }
    inputVal.init();
	bannerSlider.init();
});
