/*            ..^.^...^.^....
          ..^.^^.^.....^.^^^.^^.
        .^.^.```           ``..^...
      .^^..`                   `^.^..
     ^.^``                       `^...
   .^.^`                           ^.^.
   ^..`                             `^^`
  ^.^`         ...  .+gJ  ..ga,      .^^.
 ..^`         dqqH,.MMMMF dMMM#.      ^.^
 ^.^         +qqqH!.MMMMF dMMM#`      `.^.
 ^.`        .WqqH: .MMMMF dMMM#`       ^.^
.^^`       .dqqHD` .MMMMF dMMM#`       .^.
 .^`       dqqqS`  .MMMMF dMMM#`       ..^
 ^.`      JqqqH:   .MMMMF dMMM#`       ^..
 ^.^     .XqqH%    .MMMMF dMMM#`      `^^`
 `^.^    .XHH$`    .MMMM$ dMMM@`      ..^
  `^..      `        ??!   ??!       .^^`
   ^.^.                             .^.`
    ^.^..                         ..^.`
     `^.^.                      ..^..`
       ^^^^..                 .^.^.`
         `^^.^...         ..^^.^.`
           ``^^^^^.^.^..^.^^..``
               ```....^.```
                     `
               the1stMovement 

*************** global.js ******************
Author: Adam Siegel
Revision: .07
Last Modified: 1/20/2011
Purpose: loading the required Javascript based on what's present in the DOM. Loading scripts not loaded in the head.
Notes: please place universally needed js at the top, followed by short conditional logic, followed by includes there are examples in the comments and marked sections.
*/


//This addressed the ie6 flashing issue
try {

//works since IE6SP1

document.execCommand("BackgroundImageCache", false, true)

} catch(acold) {/*many will complain, just ignore*/}
/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * Version 2.1.2
 */

(function($){

$.fn.bgiframe = ($.browser.msie && /msie 6\.0/i.test(navigator.userAgent) ? function(s) {
    s = $.extend({
        top     : 'auto', // auto == .currentStyle.borderTopWidth
        left    : 'auto', // auto == .currentStyle.borderLeftWidth
        width   : 'auto', // auto == offsetWidth
        height  : 'auto', // auto == offsetHeight
        opacity : true,
        src     : 'javascript:false;'
    }, s);
    var html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
                   'style="display:block;position:absolute;z-index:-1;'+
                       (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
                       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
                       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
                       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
                       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
                '"/>';
    return this.each(function() {
        if ( $(this).children('iframe.bgiframe').length === 0 )
            this.insertBefore( document.createElement(html), this.firstChild );
    });
} : function() { return this; });

// old alias
$.fn.bgIframe = $.fn.bgiframe;

function prop(n) {
    return n && n.constructor === Number ? n + 'px' : n;
}

})(jQuery);

$(function(){
	/*
	 * assign anon functions, methods and vars here to be called on dom load:
	 * for example:
	 * $('body').addClass('jQuery-active');
	 * 
	 * randomSeed = Math.floor(Math.random()*1000)
	 * 
	 * use this one-liner to load js dynamically based on the dom:
	 * 
	 * if($(document).has('.js-tipsy').length ){ $.getScript( '/js/ajax/tipsy.js', function(){ $(".js-tipsy").tipsy({gravity: 'w',trigger: 'hover' });});};
	 * 
	 */
	if($('.dv-hero-cycle').length ){ 
        $('.dv-hero-cycle').data('timer',
            setInterval(function(){
                var items = $("ul.dv-chicklets li a");
                var curIndex = items.index( items.filter('.dv-active:first') ) + 1;
                if(curIndex > items.length-1 || curIndex<0 ){ curIndex = 0; }
                heroCycleChange( items.eq(curIndex) );
            },5000)
        );
    
        //When page loads...
        $("div.js-hero-pane").hide(); //Hide all content
        $("ul.dv-chicklets li:first a").addClass("dv-active").show(); //Activate first tab
        $("div.js-hero-pane:first").show(); //Show first tab content
    
        //On Click Event
        $("ul.dv-chicklets li a").click(function() {
            //Clear Out Cycle Animation
            clearInterval( $('.dv-hero-cycle').data('timer') );
            //Change Item
            heroCycleChange($(this));           
            return false;
        });

        //Hero Item Load
        var heroCycleChange = function(i$){
            $("ul.dv-chicklets li a").removeClass("dv-active"); //Remove any "active" class
            i$.addClass("dv-active"); //Add "active" class to selected tab
            $(".js-hero-pane").hide(); //Hide all tab content
            var activeTab = i$.attr("href"); //Find the href attribute value to identify the active tab + content
            $(activeTab).fadeIn(); //Fade in the active ID content
        }
	};
	
    if($('.dv-rcp02').length ){
		$("div.js-recipe-hero").hide(); //Hide all content
        $("div.dv-rcp02 li:first").addClass("dv-active"); //Activate first tab
        $("div.js-recipe-hero:first").show(); //Show first tab content
	//Recipe hero widget rcp02
		$("div.dv-rcp02 li a").click(function(){
			$("div.dv-rcp02 li").removeClass("dv-active"); //Remove any "active" class
			$(this).parent().addClass("dv-active"); //Add "active" class to selected tab
			$(".js-recipe-hero").hide(); //Hide all tab content
			var activeTab = $(this).attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});
	};
	//TAB Widgets
    if($('.dv-tw01').length ){
        $('.dv-tw01').each(function(i,currentWidget){
            var t = $(currentWidget);
            //Enable First Item
            t.find('.dv-tabs li').first().addClass('dv-active');
            t.find('.dv-tab-content').first().addClass('dv-tab-content-active');
            //Wire up each tab
            $(currentWidget).find('.dv-tabs li a').click(function(e){
                e.preventDefault();
                //Remove active class for content and tabs
                t.find('.dv-tab-content').removeClass('dv-tab-content-active')
                //Get Index of clicked tab
                var tab_index = t.find('.dv-tabs li')
                    .removeClass('dv-active')
                    .index( $(this).closest('li').addClass('dv-active') );
                //Show related content
                t.find('.dv-tab-content')
                    .removeClass('dv-tab-content-active')
                    .eq(tab_index)
                    .addClass('dv-tab-content-active');
            });
        });
    }	

	// dropdown menu script
	if($('.dv-main-nav').length ){
		$(".dv-main-nav li").mouseenter(function(){ 
			var that = ($(this));
			that.addClass("dv-hover");
			that.find('ul').bgiframe();
		}); 
		$(".dv-main-nav li").mouseleave(function() {
			$(this).removeClass("dv-hover"); 
		});
	};
	
	// Side nav script
      if($('.dv-sidenav').length ){
            if($.browser.msie && $.browser.version.substring(0,1) == "6"){
                  transition = function(selector){
                        $(selector).find("ul").css('display','block');
                  }
            } else{
                  transition = function(selector){
                        $(selector).find("ul").slideDown(500);
                        return 0;
                  }
            }
            transition("div.dv-sidenav li.dv-active");
            
            $("div.dv-sidenav li").click(function(){ 
                  if ($(this).hasClass('dv-active')){
                        return true
                  } else if ($(this).hasClass('dv-no-sub')){
                        return true
                  } else { 
				  		return true;
						
				  		/* Hidden by Amir: this was forcing users to click twice on a main category on side nav
                        $("div.dv-sidenav li ul").slideUp(10);
                        $("div.dv-sidenav li").removeClass("dv-active"); 
                        $(this).addClass("dv-active"); 
                        transition(this);

                        return false;
						*/
                  };
            }); 
      };


	// Text content re-sizer start ////////////////////////////////////////////
	if($('.dv-ar05').length ){
		
		$("div.dv-ar05 a.js-large-text").click(function(){ 
			$("div.dv-ar05").addClass('dv-large');
			return false;
		}); 
		$("div.dv-ar05 a.js-med-text").click(function(){ 
			$("div.dv-ar05").removeClass('dv-large');
			return false;
		});
	};
	//////////////////////////////Ajax calls below this line//////////////////////////
	

	//Map offset controller
	if($('.js-findcenter-map').length ){ 
		$.getScript( '/js/ajax/jquery.scrollfollow.js', function(){
			setTimeout(function(){
				
	            $( '.js-findcenter-map' ).css('position','relative').scrollFollow( {
	            	offset:10
	            } );
				
			},200); 
		});
	};
		
	//Map offset controller
	if($('.js-doctor-map').length ){ 
		$.getScript( '/js/ajax/jquery.scrollfollow.js', function(){
			setTimeout(function(){
				
	            $( '.js-doctor-map' ).css('position','relative').scrollFollow( {
	            	offset:10
	            } );
				
			},200); 
		});
	};		
	
	
	// tipsy plugin tooltips
	if($(document).has('.js-tipsy').length ){ 
		$.getScript( '/js/ajax/jquery.tipsy.js', function(){ 
			$(".js-tipsy").tipsy({
				gravity: 'n',
				trigger: 'hover',
				delayIn: 10000,
				delayOut: 10000
			});
		});
	};
	
	// validation plugin validation
    if($(document).has('.js-validate').length ){ 
		$.getScript( '/js/ajax/jquery.validate.js', function(){ 
			$(".js-validate").validate( {
				rules: {
					password: "required", password_again: {
						equalTo: "#password" 
					}
				} 
			});
		});
	};
	
	// dynamic from display snippet
    if($(document).has('.js-dynform').length ){ 
		$.getScript( '/js/ajax/jquery.dynform.js');
	};
	// Zip Code input select 
	if($(document).has('.js-zip').length ){ 
		$('.js-zip').keyup(function () { 
			this.value = this.value.replace(/[^0-9\.]/g,'');
		});
		$('.js-zip').focus(function() {// This Clears the field for the user to start entering in the Zip.
			this.value = "";
		});
		$('.js-zip').blur(function() {// This Clears the field for the user to start entering in the Zip.
			if (this.value == "") {
				this.value = "";
				$('span.error-msg').remove();
			}
		});
		function zipSubmit(){
			var zipVal = '';
			zipVal = $('.js-zip').val();
			$('span.error-msg').remove();
			
			if ( zipVal.length != 5 ) {
				$('.js-zip-error').append("<span class='error-msg'>*Your zip code is incomplete.</span>");
				return false;
			}
		}
		
		$('#js-zip-search').click(zipSubmit);
	};
	
	//////////////////////////////Ajax calls below this line//////////////////////////
	if($('.js-modal').length ){
		$('.js-modal a').openDOMWindow({ 
			borderSize:0,
			height:564, 
			width:564, 
			positionTop:400, 
			eventType:'click', 
			loader:1, 
			loaderImagePath:'/images/icons/animationProcessing.gif', 
			loaderHeight:16, 
			loaderWidth:17,
			overlayColor:'#666',
			overlayOpacity:'40',
			windowBGColor:null,
			windowSource:'ajax',
			windowHTTPType:'get'
		}); 
		
		$('.closeDOMWindow').closeDOMWindow({eventType:'click'});
	};
	
	
	
	
	
	
});
