 /*!
 * Modified: 2009-09-09 09:44:19
 * CHECKSUM[1ab195570cba528438ab422ddf9b2bc2]
 */

function trimAjaxData(data) {
  var prefix = "<!--BTJ:START-->";
  var suffix = "<!--BTJ:END-->";
  
  return data.substring(data.indexOf(prefix) + prefix.length, data.indexOf(suffix));
}


// Super Class

window.$BTJ = new function() {
	
	var $this = this;

	// Variables	
	$this.variable = true;
	
	// Constructor       
	$(function(){
	
		$this.layout();
		
		$this.initFormHints("#Md3Body");
		$this.initTooltips("#Md3Body");
		
		$this.initIE6IFrameFix();
	
		$this.initAccordion();
		$this.initCarousell();

		$this.Header.init();
		$this.Tabs.init();
		$this.Carts.init();
		$this.PopUp.init();
		$this.QuickFactsPop.init();
		
		
		$this.initAjaxLoadingCursor();
		
		// todo: move to customer service-page only
		$this.CustomerService.init();
		
		// todo: move init to checkout-page only
		$this.CheckOut.init();
		
		// todo: move init to user-signup-page only
		$this.UserSignup.init();
		
		
	});
		
		
	$this.initFormHints = function(selector) {
		$this.formHint($(selector + " .SearchFormInput"));
		$this.formHint($(selector + " .InputRounded"));
		$this.formHint($(selector + " .ShadowText"));

	};	
		
	$this.initAccordion = function() {
		$(".sections").each(function(i) {
			$(this).hAccordion(); // call jQuery function
		});
	};

	// Layout
	$(window).resize(function(){ $this.layout(); });

	$this.layout = function() {
		var winHeight = $(window).height();
		var winMin = 500;
	
		var winWidth = $(window).width();
		var winWMin = 980;
		
		// CHeck cart height
		var cartHeight = $("#ShoppingCart").height();
		if (cartHeight > winHeight || winHeight < winMin || winWidth < winWMin) {
			$("#Header").removeClass('Fixed');
		} else {
			$("#Header").addClass('Fixed');
		};

	};	

	// Added by Malin to enhance the "title" attribute on span-tags
	$this.initTooltips = function(selector) {
		$(selector + ' span[title]').qtip({ style: { name: 'standard', tip: true } })
	}

	// Formhint - changed by Malin@BTJ to work correctly when submitting values in textboxes with hintvalues
	$this.formHint = function(selector) {
		var elements = selector.find('input, textarea');
		if (!elements) {
			elements = selector;
		}
		selector.each(
			function() {
				var obj = $(this);
				var hintvalue = obj.attr('hintvalue');
				if(obj.val() != "" && obj.val() != hintvalue) {
					obj.addClass('FormHintActive');
				}
				if(obj.val() == "") {
					obj.val(hintvalue);
				}
				if (!obj.attr('title')) {
					obj.attr('title',hintvalue); 
				}
				$(this).unbind('focus');
				$(this).focus( 
					function(){
						if ($(this).val() == hintvalue) {
							$(this).val("");
						}
						$(this).addClass('FormHintActive');
					}
				);
				$(this).unbind('blur');
				$(this).blur(
					function(){	 
						if ($(this).val() == "") { 
							$(this).removeClass('FormHintActive');
							$(this).val(hintvalue);
						};
					}
				);
			}
		);
	}; 

	

	$this.initIE6IFrameFix = function() {
		var ie6 = $.browser.msie && ($.browser.version == "6.0"); 
		
		if(ie6) {
			$(".IframeFix").bgiframe();
		};
	};

	$this.initCarousell = function() {

		$('.Carousell').serialScroll({
			target:'.CarousellView',
			items:'.CarousellItem', // Selector to the items ( relative to the matched elements, '#sections' in this case )
			prev:'.PrevCarousell',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
			next:'.NextCarousell',// Selector to the 'next' button (absolute too)
			axis:'xy',// The default is 'y' scroll on both ways
			navigation:'#navigation li a',
			duration:700,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
			force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
			cycle:false,// Cycle endlessly ( constant velocity, true is the default )
					
			onBefore:function( e, elem, $pane, $items, pos ){
				e.preventDefault();
				if( this.blur )
					this.blur();
			},
			onAfter:function( elem ){
				//'this' is the element being scrolled ($pane) not jqueryfied
			}
		});
	};
	
	$this.initAjaxLoadingCursor = function() {
		// when the mouse is moved...
		$("#Md3Body").mousemove(function(event) {
			// ...set the position of the "ajax loading" image to the same position as the cursor has
			$BTJ.setAjaxProgressPosition(event);
		});
	}

	$this.setAjaxProgressPosition = function(e)
	{
            var posx = 0;
            var posy = 0;

            if (!e) var e = window.event;

            if (e.pageX || e.pageY) {
                posx = e.pageX;
                posy = e.pageY;
            }

            else if (e.clientX || e.clientY) {
                posx = e.clientX + document.documentElement.scrollLeft;
                posy = e.clientY + document.documentElement.scrollTop;
            }

            if(document.getElementById('divProgress') != null)
            {
                document.getElementById('divProgress').style.left = posx - 8 + "px";
                document.getElementById('divProgress').style.top = posy - 8 + "px";
            }
        }
        
       











}
