//****************************
//Create Tabs
//****************************
(function($){
 	$.fn.extend({ 
 		tabify: function() {
 			
    		return this.each(function() {
		
		    	//Creating a reference to the object
				var obj = $(this);
		
				//Create a reference for all headings and it's content using .next()
				//Remember to pass the object reference "obj" into the identifier.
				var headings = $('h1', obj);
				var tabContent = $('h1', obj).next();
			
				//We wan't to hide the headings and the content
				headings.addClass("hide");
				tabContent.addClass("hide");
				//But we want to show content of the first tab since it's selected by default. 
				tabContent.eq(0).removeClass("hide");;
				
				//Prepend the object with the tab container (ul).
				obj.prepend('<ul class="tabs"><\/ul>');
				
				//For every heading create an item (<li>)
				for(var i=0;i<headings.length;i++) {
					
					var sel;
					//The first object is selected by default so add class="sel" to it
					if(i == 0){
						sel = 'sel';
					}
					//Else set it to empty
					else {
						sel ="";
					}
					//the label for the tab should equal the text of the heading
					var label = headings.eq(i).text();
					//grab the id of the h2 tag in order to use as class for the li
					var tabId = headings.eq(i).attr("id");
					$("ul.tabs", obj).append('<li id="'+tabId+'-tab" class="'+sel+'"><span>' + label + '<\/span><\/li>');
				}
				
				//Create a reference to the tabs for each obj
				var tabs = $("ul.tabs li", obj);
				
				tabs.click(function() {
					
					//When a tab is clicked "de-activate" the old one
					$("ul.tabs li.sel", obj).removeClass("sel");
					tabContent.addClass("hide");
					$(this).addClass("sel");
					
					//And display the clicked tab
					var current = tabs.index($(this));
					tabContent.eq(current).removeClass("hide");
				});
    		});
    	}
	});
})(jQuery);


//login slider
function setHeight(slider) {
	var newHeight = "-"+($(slider).height()+20)+"px";//add 20 for the padding found in the styles
	$(slider).css({'margin-top': newHeight});
}

//clear field 
function clearField() {
	
		$("form").not("#myaccount").find("input").focus(function() {
			if( this.value == this.defaultValue ) {
				this.value = "";
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
		
	  
}


//**********************************
//Load Functions
//**********************************
$(document).ready( function() {
							
	$(".backtotop a").click( function() {
		$.scrollTo( '#top', 800, {} );
        return false;
    });
	
	
	//subsection tabs
	$('.tabify').tabify();
	
	
	//external link
	$("a.newwindow").click( function() {
        this.target = "_blank";
    });	
	
	$('.breadcrumb li:gt(0)').prepend('<strong>&#8250;&nbsp;&nbsp;</strong>')
	
	
	//login slider
	jQuery.fn.blindToggle = function(speed, easing, callback) {
		var h = this.height() + parseInt(this.css('paddingTop')) + parseInt(this.css('paddingBottom')) -0;
		return this.animate({marginTop: parseInt(this.css('marginTop')) < 0 ? 0 : -h}, speed, easing, callback);
	};	
	
	var slider =$("#guest");
	//setHeight(slider);
	
	$('li.stockist_login a').click(function() {
		$(slider).blindToggle(400);
	return false;
	});	
	
	
	clearField(); 	
		
	//SIZING CHART
  	$('.chart tr:odd').addClass('odd'); 
  	$('.chart tr:even').addClass('even'); 

		
});