// JQuery Background Position * @author Alexander Farkas * v. 1.02
// Used for Bridgedek Slider
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);


$(document).ready(
	function()
	{
		// Show Toggle Buttons
		$("a.toggle").css("display","block");
		$("a.toggle").addClass('toggleplus');
		

		// Hide all togglable elements.
		$(".togglable").hide();

		// Toggle Function
		$('a.toggle').click(function()
			{
				$(this).toggleClass('toggleplus');
				$(this).parent('h4').next('div.togglable').slideToggle('fast');
				return false;
			}
		);

		// Toggle h4 as well...
		$('h4.togglename').css("cursor","pointer");
		$('h4.togglename').click(function()
			{
				$(this).children('a.toggle').toggleClass('toggleplus');
				$(this).next('div.togglable').slideToggle('fast');
				return false;
			}
		);

		//Toggle Poster Content on For___ Pages
		$(".postercontent").width('0');
		$('#forposter h2 a').toggle(function()
			{
				$(".postercontent").animate({ 
		        width: "250px"}, 500 );
				return false;
			}, function()
			{
				$(".postercontent").animate({ 
		        width: "0"}, 300 );
				return false;
			}
		);

		// Zebra Tables
		$("tr:nth-child(odd)").addClass("odd");

		// Bridgedek Slider
		$('#bridgedekspeclist').append('<div id="bridgedekslider"></div><a id="bridgedektablelink" href="/img/BDchart_1.5x6x30.jpg">Download larger image of table for 1&frac12;&rdquo; &times; 6&rdquo;</a>');
		$('#bridgedekslider').css({backgroundPosition: '0 0'});
		$('#bridgedekspeclist a').click(function()
			{
				var bp = $(this).attr("class") * -381 + 381;
				var size = $(this).text();
				var dl = $(this).attr('href');
				$('#bridgedekslider').animate({backgroundPosition: '(0 ' + bp + ')'}, 600);
				$('a#bridgedektablelink').text('Download larger image of table for ' + size).attr({href:$(this).attr('href')});
				return false;
			}
		);

		// Product page tabbing.
		var newtabitems = "";
		$('.dltype').each(function(){
			tabid = $(this).attr('id');
			tabname = tabid;
			
			switch (tabid){
			case "DesignAids":tabname = "Design Aids"; break;
			case "DetailedDrawings":tabname = "Drawings"; break;
			case "AttachmentPatterns":tabname = "Attachment Patterns"; break;
			}
			
			newtabitems += '<li><a href="#'+ tabid +'">'+tabname+'</a></li>';
		});
		$('ul#prodtabber').children('li:first').after(newtabitems);
		$('ul#prodtabber a:first').addClass('active');
		$('ul#prodtabber a').click(function() {
			$('.panelcontainer').hide();
			$('ul#prodtabber a').removeClass('active');
			$(this).addClass('active');
			var lp = $(this).attr("href").split("#");
			lp = "#" + lp[1];
			$(lp).show();
			return false;
		});

		


	}
);