var headers = new Array(

  new Array(
    'http://72.47.220.238/images/uploads/headers/header_home.jpg',
    'The World\'s #1 CNC Cutting System',
    'Torchmate has the CNC machine solution that best fits your needs.  Our Torchmate CNC plasma cutting tables and CNC routers come with service and support that is second to none.  Increase your in-house production capacity with a Torchmate CNC Cutting System today.   ',
    'http://torchmate.com/products/'
  ),

  new Array(
    'http://72.47.220.238/images/uploads/headers/header_tm2x2.jpg',
    'Torchmate Growth Series™',
    'Every once in a while a product is introduced that changes the world. The purpose of the Torchmate Growth Series™ is to do just that. It is designed to allow your machine to grow with the needs of your hobby or business.',
    'http://torchmate.com/products/'
  ),

  new Array(
    'http://72.47.220.238/images/uploads/headers/header_tmx.jpg',
    'Torchmate X',
    'When customers need a complete turn-key system that can handle heavy-duty use, the Torchmate X is the answer. Whether it is cutting thick or thin plate using plasma or oxy-fuel the Torchmate X will do it with power, speed, and accuracy.',
    'http://torchmate.com/products/torchmate_x/'
  ),

  new Array(
    'http://72.47.220.238/images/uploads/headers/header_tm2.jpg',
    'Torchmate 3',
    'In response to several requests throughout the industry, the Torchmate 3 was developed featuring a gear box driven system, a 8\" forklift friendly drop-rail, and dual x axis motors. The rugged construction has the stiffness and rigidity of a steel machine weighing four times more.<br /><br /> ',
    'http://torchmate.com/products/torchmate_3/'
  ),

  new Array(
    'http://72.47.220.238/images/uploads/headers/header_tm3.jpg',
    'Torchmate 2',
    'In development for over a year, the Torchmate 2 model was an improvement to our Torchmate 1 in a variety of ways including the easy to assemble bolt together option with construction and performance comparable to industrial CNC plasma cutting machines. ',
    'http://torchmate.com/products/torchmate_2/'
  ),

  new Array(
    'http://72.47.220.238/images/uploads/headers/header_tm1.jpg',
    'Torchmate 1',
    'Intended for small shops owners and others on a budget. The Torchmate 1 kit includes: 2 axis Windows-based electronics and driver software, 269 oz. in. motors, and use a 3.4:1 reduction via timing pulleys and belts.',
    'http://torchmate.com/products/torchmate_1/'
  ),

  new Array(
    'http://72.47.220.238/images/uploads/headers/header_plasma_cutters.jpg',
    'Plasma Cutters',
    'Plasma cutting is a vital process for any metal fabrication shop. Unlike oxy-fuel, plasma can cut stainless steel, aluminum, and brass, as well as mild steel. A CNC cutting system is only as accurate as the plasma torch it guides. ',
    'http://torchmate.com/products/plasma_cutters/'
  )
);
var news = new Array(

  new Array(
    'Sign up today to begin receiving Torchmate\'s periodical newsletters.',
    '<!-- BEGIN: Signup Form Button Code from Benchmark Email Ver 2.0   --><div align=\"center\"><a href=\"http://lb.benchmarkemail.com//listbuilder/signup?66eaEV1W%252FqzeRau6Gn8Pd3K%252B8ovEW4PFVO1%252F1Sh7NFI%253D\" target=\"_new\"><img border=\"0\" src=\"http://ui.benchmarkemail.com/images/listbuilder/s8.gif\" /></a></div><!-- END: Signup Form Button Code from Benchmark Email Ver 2.0     --> <!-- BEGIN: Email Marketing By Benchmark Email   --><div align=\"center\" style=\"padding-top: 5px; font-family: Arial,Helvetica,sans-serif; font-size: 10px; color: #999999;\"><a href=\"http://www.benchmarkemail.com/email-marketing/html-email-templates\" style=\"text-decoration: none; font-family: Arial,Helvetica,sans-serif; font-size: 10px; color: #999999;\" target=\"_new\">HTML Email</a> by Benchmark</div><!-- END: Email Marketing By Benchmark Email     -->',
    'July 13, 2010',
    'Torchmate News'
  ),

  new Array(
    'Great Torchmate Forum at Pirate4x4.com',
    '<p>Pirate4x4.com holds a very informative and helpful Torchmate Forum. It\'s a great place to post questions and get your questions answered. Just follow this <a href=\"http://www.pirate4x4.com/forum/forumdisplay.php?f=125\" title=\"Pirate4x4 Torchmate Forum\" target=\"_blank\">link</a>.</p><p>As always, don\'t hesitate to call our technical support specialists at <strong>866-571-1066 x3 (Toll Free) or 775-673-2200 x3.</strong></p>',
    'August 24, 2010',
    'Torchmate News'
  ),

  new Array(
    '¿Se habla español?',
    '<p>Torchmate esta orgulloso de ofrecer a nuestros clientes el nuevo sitio <a href=\"http://www.torchmate-latino.com\" title=\"Torchmate Latino\" target=\"_blank\">www.Torchmate-Latino.com</a>. Tenimos la soluci&oacute;n en sistemas de corte CNC para toda la industria, nuestros sistems de corte est&aacute;n disponibles en todo Latino Am&eacute;rica.</p>',
    'February 8, 2011',
    'Torchmate News'
  ),

  new Array(
    'New and Used Parts Sale',
    '<p><a href=\"http://torchmate.com/statecontacts/parts.html\" title=\"new and used parts sale\" target=\"_self\"><span style=\"font-family: Arial,Helvetica,sans-serif; font-size: small;\">Torchmate is doing some spring cleaning and must clear off our shelves. Get a great deal on new and used parts. All parts will be tested before shipping. No warranty applies to the new and used parts associated with this sale. </span></a></p>',
    'May 3, 2011',
    'Featured Product'
  ),

  new Array(
    'Torchmate is Hiring',
    '<p>Torchmate is in need of sales assistants, traveling technical support  specialists and customer service representatives that have passion and  experience with CNC machinery.</p><p><a href=\"../torchmate-is-hiring/\" title=\"Torchmate is Hiring\" target=\"_self\">&gt;&gt;Find out more</a></p>',
    'October 17, 2011',
    'Torchmate News'
  ),

  new Array(
    'Financing Now Available',
    '<p>Through Lincoln Electric Capital customers now have the option of taking advantage of a custom package of financial service options to make it easy to choose the plan that\'s right for you!</p><p><a href=\"http://72.47.220.238/images/uploads/LEC_flyer.pdf\" title=\"Lincoln Electric Capital financing\" target=\"_blank\">&gt;&gt;Learn more about financing options</a></p><p><a href=\"http://torchmate.com/images/uploads/docs/LEC Lease Application.pdf\" title=\"Lincoln Electric Capital application\" target=\"_blank\">&gt;&gt;Download application</a></p>',
    'November 3, 2011',
    'Torchmate News'
  ),

  new Array(
    'Event Schedule',
    '<p>Coming up June 12 through June 14, join us at the Global Petroleum Show with our 5\'x10\' Torchmate X with tube cutting attachement. We hope to see you there! <a href=\"../about_us/event_schedule-1/\" title=\"Torchmate event schedule\" target=\"_self\">See more upcoming events here.</a></p>',
    'March 15, 2012',
    'Live Demos'
  ),

  new Array(
    'Check Out Our New Torchmate Catalog',
    '<p>Now available...2012 Torchmate Catalog with all the latest in CNC products and accessories. <a href=\"../catalog/catalog/redirectsm.htm\" title=\"Torchmate catalog\" target=\"_blank\">Click here</a>.</p>',
    'April 25, 2012',
    'Torchmate News'
  ),

  new Array(
    'Industrial Pipe Cutting Machinery',
    '<p><a href=\"http://www.vernontools.com\" title=\"Vernon Tools\" target=\"_blank\"><img alt=\"Vernon Tools\" src=\"http://torchmate.com/images/uploads/News-photo.jpg\" style=\"margin: 5px;\" /></a></p><p>Visit <a href=\"http://www.vernontools.com\" title=\"Vernon Tools\" target=\"_blank\">VernonTools.com</a> for the latest and greatest in industrial pipe cutting equipment.</p>',
    'May 21, 2012',
    ''
  )
);
var locked = false;
var cursor = 0;
var limit = headers.length-1;
var header_interval_id = 0;

function switchHeaderImage(index) {
  cursor = index;
  if(!(jQuery.browser.msie)||!(parseInt(jQuery.browser.version) == 6)) {
    $('#header .header_content').animate({ opacity: 0 }, { duration: 500, queue: false, complete: function() { $(this).remove(); 
    $('#header .header_content').animate({ opacity: 1 }, { duration: 1000, queue: false }); } });
  } else {
    $('#header .header_content').remove();
  }
  $('#header .header_learn_more').attr('href', headers[cursor][3]).attr('title', 'Learn More about '+headers[index][1]);
  $('#header .header_images').append('<img src="'+headers[cursor][0]+'" width="950" height="337" />').css({ left : 0 }).animate({left: -950 }, { duration: 500, queue: false, complete: function() { $(this).find('img:eq(0)').remove(); $(this).css('left', 0); locked = false; }});
  $('#header').prepend('<div class="header_content"><h2>'+headers[index][1]+'</h2>'+headers[index][2]+'</div>');
}
function loadRightHeaderImage() {
  cursor++;
  if(cursor>limit) {
    cursor = 0;
  }
  $('#header .bar img.active').removeClass('active');
  $('#header .bar img:eq('+cursor+')').addClass('active');
  if(!(jQuery.browser.msie)||!(parseInt(jQuery.browser.version) == 6)) {
    $('#header .header_content').animate({ opacity: 0 }, { duration: 500, queue: false, complete: function() { $(this).remove(); 
    $('#header .header_content').animate({ opacity: 1 }, { duration: 1000, queue: false }); } });
  } else {
    $('#header .header_content').remove();
  }
  $('#header .header_learn_more').attr('href', headers[cursor][3]).attr('title', 'Learn More about '+headers[cursor][1]);
  $('#header .header_images').append('<img src="'+headers[cursor][0]+'" width="950" height="337" />').css({ left : 0 }).animate({left: -950 }, { duration: 500, queue: false, complete: function() { $(this).find('img:eq(0)').remove(); $(this).css('left', 0); locked = false; }});
  $('#header').prepend('<div class="header_content"><h2>'+headers[cursor][1]+'</h2>'+headers[cursor][2]+'</div>');
}
function loadLeftHeaderImage() {
  cursor--;
  if(cursor<0) {
    cursor = limit;
  }
  $('#header .bar img.active').removeClass('active');
  $('#header .bar img:eq('+cursor+')').addClass('active');
  if(!(jQuery.browser.msie)||!(parseInt(jQuery.browser.version) == 6)) {
    $('#header .header_content').animate({ opacity: 0 }, { duration: 500, queue: false, complete: function() { $(this).remove(); 
    $('#header .header_content').animate({ opacity: 1 }, { duration: 1000, queue: false }); } });
  } else {
    $('#header .header_content').remove();
  }
  $('#header .header_learn_more').attr('href', headers[cursor][3]).attr('title', 'Learn More about '+headers[cursor][1]);
  $('#header .header_images').prepend('<img src="'+headers[cursor][0]+'" width="950" height="337" />').css({ left : -950}).animate({left: 0}, { duration: 500, queue: false, complete: function() { $(this).find('img:eq(1)').remove(); locked = false; }});
  $('#header').prepend('<div class="header_content"><h2>'+headers[cursor][1]+'</h2>'+headers[cursor][2]+'</div>');
}
$(document).ready(function() {
  header_interval_id = setInterval(function() {loadRightHeaderImage();}, 8000);
  if(!(jQuery.browser.msie)||!(parseInt(jQuery.browser.version) == 6)) {
    $('#header .header_content').css('opacity','0');
    $('#header .header_learn_more').css('opacity','0');
    $('#header .header_content').animate({ opacity: 1 }, { duration: 2000, queue: false});
    $('#header .header_learn_more').animate({ opacity: 1 }, { duration: 2000, queue: false});
  }
  $('#header .bar').animate({ bottom : 0 }, { duration: 500, queue: false });
  $.each(headers, function(i) {
    $('#header .bar').append('<img src="http://torchmate.com/images/uploads/template/header_button.gif" width="22" height="22" />');
  });
  $('#header .bar img')
    .mouseenter(function(e) {$(this).addClass('hover');})
    .mouseleave(function(e) {$(this).removeClass('hover');})
    .click(function(e) {
      if(!locked && !$(this).hasClass('active')) {
        locked = true;
        $('#header .bar img.active').removeClass('active');
        switchHeaderImage($('#header .bar img').index($(this)));
        $(this).addClass('active');
        clearInterval(header_interval_id);
      }
    })
    .eq(0).addClass('active');
    $('#header .bar div')
    .mouseenter(function(e) {$(this).addClass('hover');})
    .mouseleave(function(e) {$(this).removeClass('hover');})
    $('#header .bar .bar_left_arrow').click(function(e) { if(!locked) { locked = true; loadLeftHeaderImage(); } clearInterval(header_interval_id); })
    $('#header .bar .bar_right_arrow').click(function(e) { if(!locked) { locked = true; loadRightHeaderImage(); } clearInterval(header_interval_id); })

    //scrollingHeader();
});

var news_cursor = 0;
var news_limit = news.length-1;
var news_interval = null;
function switchNewsEntry() {
  $('#news h3').html(news[news_cursor][0]);
  $('#news .body').html(news[news_cursor][1]);
  $('#news .date').html(news[news_cursor][2]+' | ');
  $('#news .category').html(news[news_cursor][3]);
  news_cursor++;
  if(news_cursor > news_limit) {
    news_cursor = 0;
  } else if(news_cursor < 0)
    news_cursor = news_limit;
}

jQuery(document).ready(function() {
  news_interval = setInterval(switchNewsEntry, 5000);
  $('#news').mouseenter(function(e) {clearInterval(news_interval);}).mouseleave(function(e) {
    clearInterval(news_interval);
    news_interval = setInterval(switchNewsEntry, 5000);
  });
  $('#content #news .news_navigation img:eq(0)').click(function(e) {
    news_cursor -=2;
    if(news_cursor < 0)
      news_cursor += news_limit + 1;
    switchNewsEntry();
  });
  $('#content #news .news_navigation img:eq(1)').click(function(e) {switchNewsEntry();});
});

// IE5.5+ PNG Alpha Fix v2.0 Alpha: Background Tiling Support
// (c) 2008-2009 Angus Turnbull http://www.twinhelix.com

// This is licensed under the GNU LGPL, version 2.1 or later.
// For details, see: http://creativecommons.org/licenses/LGPL/2.1/

var IEPNGFix = window.IEPNGFix || {};

IEPNGFix.tileBG = function(elm, pngSrc, ready) {
	// Params: A reference to a DOM element, the PNG src file pathname, and a
	// hidden "ready-to-run" passed when called back after image preloading.

	var data = this.data[elm.uniqueID],
		elmW = Math.max(elm.clientWidth, elm.scrollWidth),
		elmH = Math.max(elm.clientHeight, elm.scrollHeight),
		bgX = elm.currentStyle.backgroundPositionX,
		bgY = elm.currentStyle.backgroundPositionY,
		bgR = elm.currentStyle.backgroundRepeat;

	// Cache of DIVs created per element, and image preloader/data.
	if (!data.tiles) {
		data.tiles = {
			elm: elm,
			src: '',
			cache: [],
			img: new Image(),
			old: {}};
	}
	var tiles = data.tiles,
		pngW = tiles.img.width,
		pngH = tiles.img.height;

	if (pngSrc) {
		if (!ready && pngSrc != tiles.src) {
			// New image? Preload it with a callback to detect dimensions.
			tiles.img.onload = function() {
				this.onload = null;
				IEPNGFix.tileBG(elm, pngSrc, 1);
			};
			return tiles.img.src = pngSrc;
		}
	} else {
		// No image?
		if (tiles.src) ready = 1;
		pngW = pngH = 0;
	}
	tiles.src = pngSrc;

	if (!ready && elmW == tiles.old.w && elmH == tiles.old.h &&
		bgX == tiles.old.x && bgY == tiles.old.y && bgR == tiles.old.r) {return;}

	// Convert English and percentage positions to pixels.
	var pos = {
			top: '0%',
			left: '0%',
			center: '50%',
			bottom: '100%',
			right: '100%'
		},
		x,
		y,
		pc;
	x = pos[bgX] || bgX;
	y = pos[bgY] || bgY;
	if (pc = x.match(/(\d+)%/)) {
		x = Math.round((elmW - pngW) * (parseInt(pc[1]) / 100));
	}
	if (pc = y.match(/(\d+)%/)) {
		y = Math.round((elmH - pngH) * (parseInt(pc[1]) / 100));
	}
	x = parseInt(x);
	y = parseInt(y);

	// Handle backgroundRepeat.
	var repeatX = { 'repeat': 1, 'repeat-x': 1 }[bgR],
		repeatY = { 'repeat': 1, 'repeat-y': 1 }[bgR];
	if (repeatX) {
		x %= pngW;
		if (x > 0) x -= pngW;
	}
	if (repeatY) {
		y %= pngH;
		if (y > 0) y -= pngH;
	}

	// Go!
	this.hook.enabled = 0;
	if (!({ relative: 1, absolute: 1 }[elm.currentStyle.position])) {
		elm.style.position = 'relative';
	}
	var count = 0,
		xPos,
		maxX = repeatX ? elmW : x + 0.1,
		yPos,
		maxY = repeatY ? elmH : y + 0.1,
		d,
		s,
		isNew;
	if (pngW && pngH) {
		for (xPos = x; xPos < maxX; xPos += pngW) {
			for (yPos = y; yPos < maxY; yPos += pngH) {
				isNew = 0;
				if (!tiles.cache[count]) {
					tiles.cache[count] = document.createElement('div');
					isNew = 1;
				}
				var clipR = Math.max(0, xPos + pngW > elmW ? elmW - xPos : pngW),
					clipB = Math.max(0, yPos + pngH > elmH ? elmH - yPos : pngH);
				d = tiles.cache[count];
				s = d.style;
				s.behavior = 'none';
				s.left = (xPos - parseInt(elm.currentStyle.paddingLeft)) + 'px';
				s.top = yPos + 'px';
				s.width = clipR + 'px';
				s.height = clipB + 'px';
				s.clip = 'rect(' +
					(yPos < 0 ? 0 - yPos : 0) + 'px,' +
					clipR + 'px,' +
					clipB + 'px,' +
					(xPos < 0 ? 0 - xPos : 0) + 'px)';
				s.display = 'block';
				if (isNew) {
					s.position = 'absolute';
					s.zIndex = -999;
					if (elm.firstChild) {
						elm.insertBefore(d, elm.firstChild);
					} else {elm.appendChild(d);}
				}
				this.fix(d, pngSrc, 0);
				count++;
			}
		}
	}
	while (count < tiles.cache.length) {
		this.fix(tiles.cache[count], '', 0);
		tiles.cache[count++].style.display = 'none';
	}

	this.hook.enabled = 1;

	// Cache so updates are infrequent.
	tiles.old = {
		w: elmW,
		h: elmH,
		x: bgX,
		y: bgY,
		r: bgR
	};
};


IEPNGFix.update = function() {
	// Update all PNG backgrounds.
	for (var i in IEPNGFix.data) {
		var t = IEPNGFix.data[i].tiles;
		if (t && t.elm && t.src) {
			IEPNGFix.tileBG(t.elm, t.src);
		}
	}
};
IEPNGFix.update.timer = 0;

if (window.attachEvent && !window.opera) {
	window.attachEvent('onresize', function() {
		clearTimeout(IEPNGFix.update.timer);
		IEPNGFix.update.timer = setTimeout(IEPNGFix.update, 100);
	});
}
