$(document).ready(function () {
    $('#site-nav-container ul').superfish({ onBeforeShow: function () {
        if ($(this).parent().hasClass('home')) {
            $('#site-nav li ul.sf-shadow').hide();
            $(this).hideSuperFishMenu();
        }
    }
    });
    $("#site-nav-container li").hover(
	  function () {
	      $(this).addClass("hover");
	  },
	  function () {
	      $(this).removeClass("hover");
	  }
	);
    $("#site-nav-container li.hover").hover(function () { $(this).fadeOut(100); $(this).fadeIn(500); });

    //SCROLL PANE
    $('#right-scroll').jScrollPane({
        scrollbarWidth: 15,
        dragMaxHeight: 67
    });

    //OUR STORY VIDEOS
    var playerLoaded = false;
    $('.video-container td a').click(function () {
        //stopPlayers();
        var flvPath = $(this).attr('href');
        if (!playerLoaded) {
            $f('video-player', "/presentation/flash/flowplayer.swf", {
                clip: {
                    url: flvPath,
                    autoPlay: true
                }
            }
					);
            $f(0).play();
            playerLoaded = true;
        } else {
            $f(0).play(flvPath);
        }
        $('#video-title').text($(this).parent().parent().find('span.video-title').text());
        $('#video-description').text($(this).parent().parent().find('span.video-description').text());
        return false;
    });

    /************************************
    *  SOCIAL MEDIA
    *************************************/
    $("li.twitter").hover(
	  function () {
	      $("#social-media-links, #social-media-links-top").addClass("bg-twitter");
	  },
	  function () {
	      $("#social-media-links, #social-media-links-top").removeClass("bg-twitter");
	  }
	);
    $("li.facebook").hover(
	  function () {
	      $("#social-media-links, #social-media-links-top").addClass("bg-facebook");
	  },
	  function () {
	      $("#social-media-links, #social-media-links-top").removeClass("bg-facebook");
	  }
	);
    $("li.opt-in").hover(
	  function () {
	      $("#social-media-links, #social-media-links-top").addClass("bg-opt-in");
	  },
	  function () {
	      $("#social-media-links, #social-media-links-top").removeClass("bg-opt-in");
	  }
	);
	
    $("li.youtube").hover(
	  function () {
	      $("#social-media-links, #social-media-links-top").addClass("bg-youtube");
	  },
	  function () {
	      $("#social-media-links, #social-media-links-top").removeClass("bg-youtube");
	  }
	);	
	/************************************
	* CALLOUTS
	*************************************/
    $(".callout").hover(
	  function () {
	      $(this).css("margin-top", "-5px");
	  },
	  function () {
	      $(this).css("margin-top", "0");
	  }
	);
    /************************************
    *  BRANDS
    *************************************/
    $("#brands-middle li").hover(
	  function () {
	      $(this).css({
			"opacity" : "1", 
			"filter" : "alpha(opacity = 100)",
			"zoom" : "1"
		});
	  },
	  function () {
	      $(this).css({
		  	"opacity": ".7",
			"filter" : "alpha(opacity = 70)",
			"zoom" : "1"
		});
	  }
	);

    //	/************************************
    //	*  HOME PAGE GALLERY
    //	*************************************/
    //	//scrollpane parts
    //		var scrollPane = $('.scroll-pane');
    //		var scrollContent = $('.scroll-content');
    //		
    //		//build slider
    //		var scrollbar = $(".scroll-bar").slider({
    //			slide:function(e, ui){
    //				if( scrollContent.width() > scrollPane.width() ){ scrollContent.css('margin-left', Math.round( ui.value / 100 * ( scrollPane.width() - scrollContent.width() )) + 'px'); }
    //				else { scrollContent.css('margin-left', 0); }
    //			}
    //		});
    //		
    //		//append icon to handle
    //		var handleHelper = scrollbar.find('.ui-slider-handle')
    //		.mousedown(function(){
    //			scrollbar.width( handleHelper.width() );
    //		})
    //		.mouseup(function(){
    //			scrollbar.width( '100%' );
    //		})
    //		.append('<span class="ui-icon ui-icon-grip-dotted-vertical"></span>')
    //		.wrap('<div class="ui-handle-helper-parent"></div>').parent();
    //		
    //		//change overflow to hidden now that slider handles the scrolling
    //		scrollPane.css('overflow','hidden');
    //		
    //		//size scrollbar and handle proportionally to scroll distance
    //		function sizeScrollbar(){
    //			var remainder = scrollContent.width() - scrollPane.width();
    //			var proportion = remainder / scrollContent.width();
    //			var handleSize = scrollPane.width() - (proportion * scrollPane.width());
    //			scrollbar.find('.ui-slider-handle').css({
    //				width: handleSize,
    //				'margin-left': -handleSize/2
    //			});
    //			handleHelper.width('').width( scrollbar.width() - handleSize);
    //		}
    //		
    //		//reset slider value based on scroll content position
    //		function resetValue(){
    //			var remainder = scrollPane.width() - scrollContent.width();
    //			var leftVal = scrollContent.css('margin-left') == 'auto' ? 0 : parseInt(scrollContent.css('margin-left'));
    //			var percentage = Math.round(leftVal / remainder * 100);
    //			scrollbar.slider("value", percentage);
    //		}
    //		//if the slider is 100% and window gets larger, reveal content
    //		function reflowContent(){
    //				var showing = scrollContent.width() + parseInt( scrollContent.css('margin-left') );
    //				var gap = scrollPane.width() - showing;
    //				if(gap > 0){
    //					scrollContent.css('margin-left', parseInt( scrollContent.css('margin-left') ) + gap);
    //				}
    //		}
    //		
    //		//change handle position on window resize
    //		$(window)
    //		.resize(function(){
    //				resetValue();
    //				sizeScrollbar();
    //				reflowContent();
    //		});
    //		//init scrollbar size
    //		setTimeout(sizeScrollbar,10);//safari wants a timeout



    //		$("#tabs").tabs({
    //			select: function(event, ui) {
    //				$("#slider").slider("value", ui.index);
    //			}
    //		});
    //		$("#slider").slider({
    //			min: 0,
    //			max: $("#tabs").tabs("length") - 1,
    //			slide: function(event, ui) {
    //				$("#tabs").tabs("select", ui.value);
    //			}
    //		});

    //		
    //		
    //		/************************************
    //		*  CYCLE THROUGH THE GALLERY
    //		*************************************/
    //		 $('.scroll-content').cycle({
    //			fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    //		});

    /************************************
    *  MODAL WINDOW
    *************************************/
    //select all the a tag with name equal to modal
    $('a[rel=modal]').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();

        //Get the A tag
        var id = $(this).attr('href');

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect		
        $('#mask').fadeIn(500);
        $('#mask').fadeTo("normal", 0.7);

        $('#mask').css('left', '-' + $('#mask').offset().left + 'px');
        $('#mask').css('top', '-' + $('#mask').offset().top + 'px');

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);
        window.scroll(winW / 2, 0);

        //transition effect
        $(id).fadeIn(500);
    });

    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
    });

    //if mask is clicked
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    });


    /******************************************************
    *  GALLERIA SETTINGS FOR OUR STORY/FROM FIELD TO TABLE
    *******************************************************/
    var galleries = $('.ad-gallery').adGallery();
    $('#switch-effect').change(
      function () {
          galleries[0].settings.effect = $(this).val();
          return false;
      }
    );
    $('#toggle-slideshow').click(
      function () {
          galleries[0].slideshow.toggle();
          return false;
      }
    );
	
/*================================================
 Add class for Alternative Background on 
 Our Story Callouts
================================================*/
$('.our-story #story-column1 .callout-item:odd').addClass('layout-2');
$('.our-story #story-column2 .callout-item:even').addClass('layout-2');


/*================================================
 Gallery Carousel
================================================*/
$('#wws.home .carousel').randomize('li');

$('#wws.home .carousel').jcarousel({
    scroll: 1
});




/*================================================
 Add First/Last Class
================================================*/
/*---- UL/OL List Items ----*/
$('#wws ul li:first-child, #wws ol li:first-child').addClass('first');
$('#wws ul li:last-child, #wws ol li:last-child').addClass('last');

/*---- DL List Items ----*/
$('#wws dl dt:first-child, #wws dl dd:first-child').addClass('first');
$('#wws dl dt:last, #wws dl dd:last-child').addClass('last');

/*---- Gallery Carousel Slides ----*/
$('#wws.home .carousel ul li:last-child').removeClass('last');

if (jQuery.browser.msie && $.browser.version == 7) {
	$('#wws.home .jcarousel-item').css({'margin-top' : '-14px'});
}

/*================================================
 File Input Replacement
================================================*/
$("#wws .upload-video input[type=file]").filestyle({
    image: "/presentation/schwebels/images/promotions/we-want-schwebels/btn-browse.png",
    imageheight: 38,
    imagewidth: 91,
    width: 296
});


/*================================================
 Clear Gallery Listing Row Margins
================================================*/
$('#wws div.gallery').randomize('div.gallery-item');

$('#wws div.gallery div.gallery-item').each(function(indexItem) {
	$(this).addClass('g-' + indexItem);
	
});

$('#wws div.gallery .gallery-item:nth-child(3n)').css({'margin-right' : '0px'});
$('#wws div.gallery .gallery-item:nth-child(10n), #wws div.gallery .gallery-item:nth-child(11n), #wws div.gallery .gallery-item:nth-child(12n)').addClass('last-row');
$('#wws div.gallery .gallery-item:last-child').addClass('last-listing');



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

/*---- Browse Button ----*/
$('#wws .upload-video div').hover(
function () { $(this).addClass("hover"); },
function () { $(this).removeClass("hover");}
);



/*================================================
 WWS FAQ Toggle
================================================*/
$("#wws.faq div.faq-item:first").children(".answer").show();

$("#wws.faq .faq-item .question h3").click(function(){
$(this).closest(".faq-item").toggleClass("active").children(".answer").slideToggle(500);
});


/*================================================
 WWS Home Text Shadow
================================================*/
var shadowOptions = { x: 1, y: 1, radius: 2, color: "#000000" }

if ($.browser.msie) {
    $('#wws.home .section.winners-announcement p, #wws.home .section.winners-announcement p a, #wws.home .section.vote-now p, #wws.home .section.vote-now p a, #wws.winners .section.header p, #wws.winners .wws-winners .section.prize-grand ul li').textShadow(shadowOptions);
}







});





/*======================================
 FUNCTIONS - added here as to not need
 a recompile by adding a new file
======================================*/
function formatURL(url) {
    url = url.toString();
    if (url.toLowerCase().indexOf(".aspx") == -1)
    {
        return url + ".aspx";
    }

    return url;
}
