$(document).ready(function(){
	DD_roundies.addRule('.promo A, .productSection, .headerMain, .steps, .list, .readAll, .infoGo', '0 0 3px 3px', true);
	DD_roundies.addRule('.moreInfo, #generic .contentSubNav, #promotion .contentSubNav, .newsHalf', '3px 3px 0 0', true);
	DD_roundies.addRule('.contentSubNav', '0 3px 0 0', true);
	DD_roundies.addRule('.signUp, #siteFooter, .highLighted, #search, .latest, .box, .contentArea .products, .moreInfo, #save .moreInfo UL LI, .contentArea .grad, .archive', '3px', true);
	$("a[rel='ext']").each(function(){
		$(this).attr("target","_blank");
		$(this).attr("title","This link will open in a new window/tab.");
	});
	if($(".imgList").length>0){
		$('.toShow').html('<p>Roll over image for more info and options</p>');
		$('.imgList').hover(function(){
			if($(".galGo").length==0){
				imgTitle = $(".imgList #img_0 IMG").attr("title");
				$(".title").html(imgTitle);
				imgHiRes = $(".imgList #img_0 IMG").attr("longdesc");
				if(imgHiRes!="false"){
					$("#viewBiggerImage").attr({"class":"enabled"});
					$("#viewBiggerImage").attr({"href":"/images/"+imgHiRes+".jpg"});
				} else {
					$("#viewBiggerImage").attr({"class":"disabled"});
					$("#viewBiggerImage").attr({"href":""});
				}
			}
			$('.imgGallery').fadeIn().addClass('galGo');
		 });
		(function($) {
			Gallery = "";
			totalImages=0;
			curImg = 0;
			$.photoGallery = {
				bindList: function(){
					totalImages=$(Gallery+" LI").length;
					$.each($(Gallery+" LI"),function(i,item){
						$(this).attr("id","img_"+i);
					});
				},
				createGallery: function(galleries){
					Gallery="."+galleries;
					$.photoGallery.bindList();
					$(".arrows .current").html("1");
					$(".arrows .total").html(totalImages);
					$(".imgGallery .next").click(function(){
						//alert(curImg+" < "+totalImages)
//						var curImg = parseInt($(".arrows .current").html());
						if((curImg+1)<totalImages){
							curImg++;
							$(".arrows .current").html((curImg+1));
							$(".imgList LI").each(function(){$(this).hide();});
							$(".imgList #img_"+(curImg)).fadeIn();
							imgTitle = $(".imgList #img_"+(curImg)+" IMG").attr("title");
							$(".title").html(imgTitle);
							imgHiRes = $(".imgList #img_"+(curImg)+" IMG").attr("longdesc");
							if(imgHiRes!="false"){
								$("#viewBiggerImage").attr({"class":"enabled"});
								$("#viewBiggerImage").attr({"href":"/images/"+imgHiRes+".jpg"});
							} else {
								$("#viewBiggerImage").attr({"class":"disabled"});
								$("#viewBiggerImage").attr({"href":""});
							}
						}
						return false;
					});
					$(".imgGallery .prev").click(function(){
//						var curImg = parseInt($(".arrows .current").html());
						if(curImg>0){
							curImg--;
							$(".arrows .current").html((curImg+1));
							$(".imgList LI").each(function(){$(this).hide();});
							$(".imgList #img_"+(curImg)).fadeIn();
							imgTitle = $(".imgList #img_"+(curImg)+" IMG").attr("title");
							$(".title").html(imgTitle);
							imgHiRes = $(".imgList #img_"+(curImg)+" IMG").attr("longdesc");
							if(imgHiRes!="false"){
								$("#viewBiggerImage").attr({"class":"enabled"});
								$("#viewBiggerImage").attr({"href":"/images/"+imgHiRes+".jpg"});
							} else {
								$("#viewBiggerImage").attr({"class":"disabled"});
								$("#viewBiggerImage").attr({"href":""});
							}
						}
						return false;
					});
				}
			}
		})(jQuery);
	$.photoGallery.createGallery("imgList");
	$("#viewBiggerImage").lightBox();
	}
	if($("#contact #hear").length>0){
		$("#hear").change(function(){
			//if ($(".generated").lenght > 0)
			if ($("#contacForm").attr("action").search("#jump") < 0)$("#contacForm").attr("action", $("#contacForm").attr("action") + "#jump");
			$("#contacForm").submit();
			//if ($(this).val() == "Received a mailing") $("form").submit();
			//else if ($("#contact #MailingCode").length>0)window.location.href = window.location.href;
			
		})	
	}
	
    var specialOffers = $('.specialOfferMain');
    
    if (specialOffers.length > 1) fadeInNext(specialOffers,0);
    
    function fadeInNext(elements,i){
        var n = (i == elements.length - 1) ? 0 : i+1;
        $(elements[i]).fadeOut('slow');
        $(elements[n]).fadeIn('slow',function(){
            setTimeout(function(){
                fadeInNext(elements,n);
            },4000);
        });
    }
    
});
