$(function(){
	
	// Dropdown Menu
	function showMenu() { $(this).addClass('active').children('ul').fadeIn(200); }
	function hideMenu() { $(this).removeClass('active').children('ul').fadeOut(100); }
	$('#nav ul li').hoverIntent(showMenu, hideMenu);
	// --------->

});
    
  jQuery(function($){
      $(".tweet").tweet({
        avatar_size: 32,
        count: 1,
        username: "teatreebaybev",
        template: "{text}"
      });
    }).bind("loaded", function(){
      $(this).find("a.tweet_action").click(function(ev) {
        window.open(this.href, "Retweet",
                    'menubar=0,resizable=0,width=550,height=420,top=200,left=400');
        ev.preventDefault();
      
      
      
      });});	
    jQuery(document).ready(function() {
    jQuery('span.chief').css('opacity', 0.3);
	jQuery('span.chief').hover(function(){ jQuery(this).stop().animate({opacity: 1, height: 150, top: '-153px'}, 500); }, function(){ jQuery(this).stop().animate({opacity: 0.3, height: 80, top: '-80px'}, 300); })});
    
  $(document).ready(function() {
						   					   
		$('#accordion').accordion({
			event: 'click',
			active: '.selected',
			selectedClass: 'active',
			animated: "bounceslide",
			header: "dt",
			alwaysOpen: false,
			autoheight: false
		}).bind("change.ui-accordion", function(event, ui) {
			jQuery('<div>' + ui.oldHeader.text() + ' hidden, ' + ui.newHeader.text() + ' shown</div>').appendTo('#log');
		});		
			
		var opensitemap = '[+] View Sitemap';
		var closesitemap = '[-] Hide Sitemap';
		$("#sitemap-content").hide();	
		$("span.toggler").click(function() {
										   
		 if ($("#sitemap-content").is(":hidden")){
			 $("#sitemap-content").slideDown(500);			 
			 $(this).html(closesitemap);
			 
			var x = 1800; 
			var t = 800; 
			$("html, body").animate({ scrollTop: x }, t);
        	return false;
       
	   }
		 else{
			$("#sitemap-content").slideUp(1200);		
			$(this).html(opensitemap);
		 }
															
	});
	jQuery(document).ready(function() {
    jQuery('#primary-catergories ul li').css('opacity', 1);
	jQuery('#primary-catergories ul li').hover(function(){ jQuery(this).stop().animate({opacity: 0.6}, 300); }, function(){ jQuery(this).stop().animate({opacity: 1}, 300); })});
	


// Newsletter pop up
	var toggleNews = jQuery('.newsletterSign'); 
	var contentNews = jQuery('#box');
	var overlayNews = jQuery('#overlay');
	
	toggleNews.live('click', function(){
	
		contentNews.parent().addClass('newsSignUp');
	
		overlayNews.css('opacity', 0.75).show();
		
		jQuery('.msg').html('Newsletter Sign Up ');
		
		jQuery('#boxCon').show();	
		contentNews.show();
		
		jQuery.ajax({
      		beforeSend: function() { jQuery('#loading').show();},
      		success: function() {
      			jQuery('#loading').hide();     
      			jQuery('#close, .closetxt').show(); 			
				contentNews.delay(2000).append('<iframe height="140" id="ajax" src="http://www.ttbfiles.co.uk/oct2011/subscribe.html" frameborder="0" scrolling="no"></iframe>');
     		},
     		error: function() { contentNews.html('Oops! Something went wrong :( - please try again.'); }
     	});
		
	});
	
	jQuery('#close, .close').live('click', function(){hideNewsOverlay();return false;});	
	jQuery('#overlay').click(function(){hideNewsOverlay();})
	function hideNewsOverlay() {contentNews.hide();overlayNews.hide();jQuery('#ajax').remove(); jQuery('#close, .closetxt').hide(); }
	
	jQuery(document).keyup(function(e) {
  		if (e.keyCode == 27) { hideNewsOverlay(); }   // esc
	});

	// Overlay
		
		
	var toggle = jQuery('.sizeChart'); 
	var content = jQuery('#box');
	var overlay = jQuery('#overlay');
	
    //Define margin for center alignment (vertical
    var popMargTop = (jQuery('#boxCon').height()) / 2;
    var popMargLeft = (jQuery('#boxCon').width()) / 2;

    //Apply Margin to Popup
    jQuery('#boxCon').css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });		
	
	toggle.live('click', function(){
	
		var tag = jQuery(this).attr('rel');
		content.parent().removeClass('newsSignUp');
		overlay.css('opacity', 0.75).show();
		jQuery('.msg').html('You are viewing the Size Charts');
		jQuery('#boxCon').show();
		content.show();
		
		jQuery.ajax({
      		beforeSend: function() { jQuery('#loading').show();},
      		success: function() {
      			jQuery('#loading').hide();     
      			jQuery('#close, .closetxt').show(); 			
				content.delay(2000).append('<iframe class="sizes" id="ajax" src="http://www.ttbfiles.co.uk/sizecharts/sizes.html#'+tag+'" frameborder="0"></iframe>');
     		},
     		error: function() { content.html('Oops! Something went wrong :( - please try again.'); }
     	});
     	
     	return false;
		
	});
	
	jQuery('#close, .close').live('click', function(){hideOverlay();return false;});	
	jQuery('#overlay').click(function(){hideOverlay();})
	function hideOverlay() {content.hide();overlay.hide();jQuery('#ajax').remove(); jQuery('#close, .closetxt').hide(); jQuery('#boxCon').hide();}
	
	jQuery(document).keyup(function(e) {
  		if (e.keyCode == 27) { hideOverlay(); }   // esc
	});
	
			jQuery('#cat_hdr b:first').remove();
		jQuery('#prod_tbl b:eq(1)').remove();
		
		jQuery('#prod_tbl td:first').css({cursor: 'pointer', paddingLeft: '20px'});
	
	
});
