jQuery.noConflict();
jQuery(document).ready(function($) {
    $('#nav li').hover(
		function() {
		    $('div.flyout', this).show().end().children('a:first').addClass('active');
		    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
		        var ieversion = new Number(RegExp.$1);
		        if (ieversion < 7) {
		            $('.content-wide, #sap-main.gallery').css({ zIndex: -1 });
		        }
		    }
		},
		function() {
		    $('div.flyout', this).hide().end().children('a:first').removeClass('active');
		    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
		        var ieversion = new Number(RegExp.$1);
		        if (ieversion < 7) {
		            $('.content-wide, #sap-main.gallery').css({ zIndex: 1 });
		        }
		    }
		}
	);

    //		function showTip(which) {
    //		    var tipPos = $(which).text();
    //		    tipPos = parseInt(tipPos);
    //		    switch (tipPos) {
    //		        case 1:
    //		            var text = 'Welcome';
    //		            break;
    //		        case 2:
    //		            var text = 'Totally Tie-Dye';
    //		            break;
    //		        case 3:
    //		            var text = 'Duck Products';
    //		            break;
    //		        case 4:
    //		            var text = 'Duck Tape Club';
    //		            break;
    //		        default:
    //		            var text = 'Welcome';
    //		    }
    //		    var arrowPos = tipPos * 20 - 9;
    //		    var tip = '<div id="rotator-tip">' + text + '<div id="rotator-tip-arrow" style="left:' + arrowPos + 'px"></div></div>';
    //		    $(which).before(tip);
    //		}

    //    function hideTip() {
    //        $('#rotator-tip').remove();
    //    }

    //    $('#rotator-nav a').hover(function() {
    //        showTip(this);
    //    },
    //		function() {
    //		    hideTip();
    //		}
    //	);
    $('input:text:not(.dont-replace)').each(function() {
        var boxID = $(this).attr('id');
        var boxLabel = $(this).parent().find('label[for="' + boxID + '"]');
        boxLabel.hide();
        if ($(this).val() === '') {
            var boxText = boxLabel.text();
            $(this).val(boxText);
        } else {

            var boxText = $(this).val();
        }

        $(this).focus(function() {
            if ($(this).val() === boxText) {
                $(this).val('')
            }
        });
        $(this).blur(function() {
            if ($(this).val() === '') {
                $(this).val(boxText);
            }
        });
    });
    if ($('#home-rotator').length > 0) {
        $('#home-rotator').after('<div id="rotator-nav">').cycle({
            fx: 'fade',
            timeout: 10000,
            cleartype: 1,
            pager: '#rotator-nav'
        });
    }
    $('a[rel=new-window-facebook]').click(function() {
        window.open($(this).attr('href'), 'sharer', 'toolbar=0,status=0,width=626,height=436');
        return false;
    });



/*================================================
 Last Ducktivity Listing Item
================================================*/
$('#ducktivity-listing .ducktivity-category:last').addClass('last');


/*================================================
 Ducktivity Image Rotator
================================================*/
if ($('#ducktivity-rotator').length > 0) {
    $('#ducktivity-rotator').after('<div id="ducktivity-rotator-nav">').cycle({
        fx: 'fade',
        timeout: 10000,
        cleartype: 1,
        pager: '#ducktivity-rotator-nav'
    });
}


/*================================================
 File Input Replacement
================================================*/
if($().filestyle) {
     $("#ducktivity-content .browse input[type=file]").filestyle({
        image: "/images/btn-browse.png",
        imageheight: 24,
        imagewidth: 89,
        width: 298
    });
}


/*================================================
 IE Hover Fix
================================================*/
$("input[type=button]").hover(
function () { $(this).addClass("hover"); },
function () { $(this).removeClass("hover"); }
);


/*================================================
 Add First/Last Class to List Items
================================================*/
$('ul li:first-child').addClass('first');
$('ul li:last-child').addClass('last');

$('#ducktivity-home .ducktivity-category:first-child').addClass('first');


/*================================================
 Pink Products
================================================*/
$(".main-nav td.left-nav-selected a:contains('Pink Products')").css({"color" : "#f12c6e"});
$(".main-nav td.left-nav-parent a:contains('Pink Products')").css({"color" : "#f12c6e"});
$(".content-wide #content-wide-header h1:contains('Pink Products')").css({"color" : "#f12c6e"});
$("#nav li .flyout .left li a:contains('Pink Products')").css({"color" : "#f12c6e"});


/*================================================
 Promotions
================================================*/
/*---- Link to College Duck Tape Photo Contest Facebook Tab ----*/
$(".main-nav td.left-nav-inactive a:contains('College Duck Tape School Spirit Photo Contest')").attr('href', 'https://www.facebook.com/ducktape?sk=app_146310478789354').attr('target', '_blank');
//$('.featured-promotion-left img[src="~/media/bubblewrap-birthday-promo-322x215.ashx"]').parent().attr('href', 'https://www.facebook.com/ducktape?sk=app_146310478789354').attr('target', '_blank');
$('.featured-promotion-left img[src="~/media/Promotions/College Duck Tape Contest/collegeducktape-promo-landing.ashx"]').parent().attr('href', 'https://www.facebook.com/ducktape?sk=app_146310478789354').attr('target', '_blank');
$('#nav li .flyout a:contains("College Duck Tape School Spirit Photo Contest")').attr('href', 'https://www.facebook.com/ducktape?sk=app_146310478789354').attr('target', '_blank');


$("#nav li a span:contains('Where To Buy')").parent().parent().addClass('navWhereToBuy');

/*================================================
 Remove Broken Link from Main Nav
================================================*/
$("#nav li .flyout .right li a:contains('Duck Tape Club Home')").parent().addClass('hide');


/*================================================
 Check if there is a Ducktivity Step Image
================================================*/
$('#ducktivity .ducktivity-step div.image a:empty, #ducktivity .ducktivity-step div.image:empty').closest('div.ducktivity-step').addClass('no-image');


/*================================================
 Ducktivity Form Inputs
================================================*/
$('#ducktivity .ducktivity-step .text-input').each(function(){
    var thisTitle = $(this).attr('title');
    if ($(this).val() == '')
	    $(this).val(thisTitle);
});
	
$('#ducktivity .ducktivity-step .text-input').focus(function(){
	if($(this).val() == $(this).attr('title') ) {
		$(this).val('');
	}
	$(this).addClass('edit');
});
	
$('#ducktivity .ducktivity-step .text-input').blur(function(){
	if($(this).val() == '' ) {
		$(this).val($(this).attr('title'));
		$(this).removeClass('edit');
	}
});


var ducktivitySteps = 0;
$('#ducktivity .ducktivity-step').each(function() {
	ducktivitySteps++
});

/*
$('#ducktivity .add-step').live('click',function() {
	ducktivitySteps += 1;
	var addDucktivityStep = "<div class=\"ducktivity-step\">";
	addDucktivityStep += "<div class=\"count\">" + ducktivitySteps + "</div>";
	addDucktivityStep += "<h3>Step " + ducktivitySteps + " of your Ducktivity<br />What is Step " + ducktivitySteps + " of your Ducktivity?</h3>"
	addDucktivityStep += "<textarea class=\"text-input\" title=\"Tell us how this step works (ie: Cut several strips of duct tape - about 2 inches each.)\"></textarea>";
	addDucktivityStep += "<div class=\"browse\">";
	addDucktivityStep += "<input type=\"file\" class=\"text-input\" />";
	addDucktivityStep += "<span class=\"note\">The image you upload must be a maximum file size of 3MB and in .JPG format</span>";
	addDucktivityStep += "</div>";	
	addDucktivityStep += "<input type=\"button\" value=\"Save this Step\" class=\"save-step\" />";
	addDucktivityStep += "</div>";

	$(addDucktivityStep).insertBefore($(this));
});
*/


/*================================================
 Text Shadow
================================================*/
var footerSitemapShadow = { x: 1, y: 1, radius: 2, color: "#002612" }
var footerNavShadow = { x: 1, y: 1, radius: 2, color: "#002512" }

/*
if ($.browser.msie) {
	if($().textShadow) {	
    	$('.footer-section h5, .footer-section a').textShadow(footerSitemapShadow);
		$('#footer a').textShadow(footerNavShadow);
	}
}
*/


/*================================================
 Coupon
================================================*/

/*---- Selectbox Replacement ----*/
/*$('div#coupon select.selectbox').sSelect({
	ddMaxHeight: '300px'
});
*/

/*---- Form Checkboxes ----*/
$('div#coupon input:checkbox').after('<a href="#" class="check">Check</a>');
$('div#coupon input:checked').parent().addClass('checked');

$('div#coupon span.checkbox a.check').click(function(event) {
	event.preventDefault();
	
	if($(this).parent().find('input:checkbox').is(':checked')){
		$(this).parent().removeClass('checked');	
		$(this).parent().find('input:checkbox').removeAttr('checked');
	}
	else {
		$(this).parent().addClass('checked');
		$(this).parent().find('input:checkbox').attr('checked', 'checked');
	}		

});



//End jQuery	
});
