$(document).ready(function() {

	$('#mlsignup').click(function() {
  		$('.mlsignup_form').slideToggle();
  		return false;
  	});
		
	//External Links
	
	$("a[href^='http']").attr('target','_blank');
	$("a[rel='external']").attr('target','_blank');
	
	
	//Fancybox Calls
	
	$("#tip5").fancybox({
		'scrolling'		: 'no',
		'titleShow'		: false,
		'padding'		: 0
	});
	
	$("#enlarger").fancybox({
		'scrolling'		: 'no',
		'titleShow'		: false,
		'padding'		: 0
	});
	// Scroll Announcements
	
	$(function() {
			    var ele   = $('#scroll');
			    var speed = 25, scroll = 20, scrolling;
			    
			    $('#scroll-up').click(function() {
			        // Scroll the element up
			        ele.scrollTop( ele.scrollTop() - scroll );
			    });
			    
			    $('#scroll-down').click(function() {
			        // Scroll the element up
			        ele.scrollTop( ele.scrollTop() + scroll );
			    });
			    
			    $('#scroll-up, #scroll-down').bind({
			        click: function(e) {
			            // Prevent the default click action
			            e.preventDefault();
			        }
			    });
			});
			
			
	// Hide unused link paragraphs in 'Our Team' Web App
	
	$(".special").each(function(){
		if ($(this).find("a").attr("href") == ""){
			$(this).hide();
		}
	});
	
	// Hide sale prices if product is not on sale
	
	$('td.productItem').each(function(){
		if ($(this).find('h3').hasClass('0')) {
			$(this).find('span.isOnSale').hide();
		} else {
			$(this).find('span.isOnSale').show();
		}
	
	});
	
	// Hide CC Fields/PO dependant on Radio Selection
	$("input[name$='PaymentMethodType']").click(function() {
        var paymentVal = $(this).val();

        if(paymentVal == 1){
        $('.cc').show();
			$('#paymentdiv').show();
			$('.po').hide();
			
		} else if(paymentVal == 2){
		$('.cc').hide();
			$('.po').show();
			$('#paymentdiv').hide();
		
		}
    });

	/*
$("input[@name=PaymentMethodType]").click(function(){
		alert('Function Called');
		var paymentVal = $("input[@name=PaymentMethodType]:checked").val();
	});
*/
	
});

// Start rollOver Image Code

function initRollovers() {

  if (!document.getElementById) return

    var aPreLoad = new Array();
    var sTempSrc;
    var aImages = document.getElementsByTagName('img');

    for (var i = 0; i < aImages.length; i++) {
    if (aImages[i].className == 'imgover') {
      var src = aImages[i].getAttribute('src');
      var ftype = src.substring(src.lastIndexOf('.'), src.length);
      var hsrc = src.replace(ftype, '_over'+ftype);

      aImages[i].setAttribute('hsrc', hsrc);

      aPreLoad[i] = new Image();
      aPreLoad[i].src = hsrc;

      aImages[i].onmouseover = function() {
      sTempSrc = this.getAttribute('src');
      this.setAttribute('src', this.getAttribute('hsrc'));
    }

    aImages[i].onmouseout = function() {
      if (!sTempSrc) sTempSrc = this.getAttribute('src').
          replace('_over'+ftype, ftype);
        this.setAttribute('src', sTempSrc);
      }
    }
  }
}

// Keep Cart In View

window.onscroll = function()
{
    if( window.XMLHttpRequest ) {
        if (document.documentElement.scrollTop > 473 || self.pageYOffset > 473) {
            $('#scrollingDiv').css('position','fixed');
            $('#scrollingDiv').css('top','20px');
        } else if (document.documentElement.scrollTop < 473 || self.pageYOffset < 473) {
            $('#scrollingDiv').css('position','absolute');
            $('#scrollingDiv').css('top','280px');
        }
    }
}


window.onload = initRollovers;


