/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


//JQuery Setup
$(function(){
 
//Important functions to fire first!
//-------------------------------------------------------------------------------
  	//IE6 duct tape
  	//detects if browser is IE by checking leadingWhitespace property. 
  	//See: http://docs.jquery.com/Utilities/jQuery.support
	var fancyHover = $.support.leadingWhitespace;
	if(fancyHover == false) {//browser is IE, use script
		$('#nav ul li').bind('mouseenter mouseleave', function(){
			$(this).toggleClass('sfhover');
		});	
	}
	
	//IE6 Upgrade Warning
	//-- requires:
	//-- <script type="text/javascript" src="http://1.scripts.sesamehost.com/scripts/jquery1.3.2.min.js"></script>
	//-- <script type="text/javascript" src="http://9.scripts.sesamehost.com/scripts/jquery.cookie.js"></script>
	
	//cookies
		
		//set cookie handler
		var alertBox = $.cookie('ie_alert');
		//if cookie val "noshow" then hide message - user has already seen this message!
		if(alertBox == 'noshow') {
			$('#alert').css('display', 'none');
		}else{
			$('#alert').css('display', 'block');
		}

	//click to close behavior
		$('.ie-alert-link').click(function() {
			$('#alert').slideToggle("slow");
			$.cookie('ie_alert', 'noshow', { expires: 14 });
		});

	//-- /end ie6 warning
	
	
	// Some effects rely on an element to be initially hidden,
	// but we only hide them if the user has javascript
	$('.jshide').addClass('hide');
	
	// Fancybox Videos =================== >
	$("a.fancy-practice").fancybox({
		'frameWidth': 600,
		'frameHeight': 355,
		'zoomSpeedIn': 0,
		'zoomSpeedOut': 0,
		'overlayShow': true,
		'callbackOnClose': function() {$("#fancy_content").empty(); },
		'hideOnContentClick': false
	});
	
	$("a.fancy-tour").fancybox({
		'frameWidth': 600,
		'frameHeight': 477,
		'zoomSpeedIn': 0,
		'zoomSpeedOut': 0,
		'overlayShow': true,
		'callbackOnClose': function() {$("#fancy_content").empty(); },
		'hideOnContentClick': false
	});
	
	$('#video-practice').flash(
		{ 
		  src: 'video/flvPlayer.swf',
			width: 600,
		  height: 355,
		  wmode: 'transparent',
		  flashvars: { 
			flvToPlay: 'DISCHINGER_PRACTICE_VIDEO.flv',
			autoStart: 'true',
			scaleMode: 'full',
			hiddenGui: 'false',
			showScaleModes: 'false'
		  }
		},
		{ version: 8 }
	);
	
	$('#video-tour').flash(
		{ 
		  src: 'video/flvPlayer.swf',
			width: 600,
		  height: 477,
		  wmode: 'transparent',
		  flashvars: { 
			flvToPlay: 'office-tour.flv',
			autoStart: 'true',
			scaleMode: 'full',
			hiddenGui: 'false',
			showScaleModes: 'false'
		  }
		},
		{ version: 8 }
	);

// Image Replacement	
//-------------------------------------------------------------------------------
	
	//SIFR
	//--- <script type="text/javascript" src="http://2.scripts.sesamehost.com/scripts/jquery.flash.js"></script>
	$('h1.sifr').flash(
        { 
            src: 'flash/stone_sans2.swf',
            wmode: 'transparent', 
            flashvars: { 
                css: [
                    '* { color: #000040;}',
                ].join(' ')
            }
        },
        { version: 7 },
        function(htmlOptions) {
            htmlOptions.flashvars.txt = this.innerHTML;
            this.innerHTML = '<div>'+this.innerHTML+'</div>';
            var $alt = $(this.firstChild);
            htmlOptions.height = $alt.height();
            htmlOptions.width = $alt.width();
            $alt.addClass('alt');
            $(this)
                .addClass('flash-replaced')
                .prepend($.fn.flash.transform(htmlOptions));						
        }
    );


	//jcIR 
	//--- requires: 
	//--- <script type="text/javascript" src="http://4.scripts.sesamehost.com/scripts/jquery.pngFix.js"></script>
	//--- <script type="text/javascript" src="http://2.scripts.sesamehost.com/scripts/jquery.jcIR.js"></script>

	//check if images are enabled then run replacement
	$('<img src="images/pixel.gif'+ '#' + Math.random() + '"/>').load(function() {
		$('.jcir.logo').jcIR({
			image_dir: 'logos',//no slashes
			image_ext: '.jpg',//file extention of replacement image
			elem_width: '208',//width of element being replaced
			elem_height: '54'//height of el;ement being replaces
		});
	});

	//---
	

// Utilities
//-------------------------------------------------------------------------------
	//PNG fix for IE6
	//--- requires
	//--- <script type="text/javascript" src="http://4.scripts.sesamehost.com/scripts/jquery.pngFix.js"></script>
	$(document).pngFix(); 
	
	//Anti-spam email obfuscator
	if ($('span.hidden-email')) {
		// load the cufon library
		$.ajax({
			type: 'GET',
			url: 'scripts/jquery.jcAntiSpam.js',
			cache: true,
			success: function() { 
				$("span[rel^='suzi']").jcAntiSpam({
					emailCommonName: 'suzi@dischingerteam.com',//Name displayed in link text, e.g., 'Email So-And-So'
					emailName: 'suzi',//First half of primary email address; before "@" symbol
					emailDomain: 'dischingerteam.com',// Full Primary email domain name
					emailCcName: '',//First half of CC email address; before "@" symbol
					emailCcDomain: ''//CC email domain name
				}); 
			},
			dataType: 'script',
			data: null
		});
	}

	
//Toggle functions
//---------------------------------------------------------------------------------
	
	// Show only when javascript is available
	$('.toggle-link').css('display','block');

	//hide lists first!
	//$('#toggle-content li div').css('display','none');	
	$('#toggle-content dl').css('display','none');	

	//toggle
	function toggleInfoContent(id){
		if($('#' + id).css('display') != 'none'){
		  $('#' + id).fadeOut('fast');
		}else{
		  //$("#toggle-content li div").hide();
		  $("#toggle-content dl").fadeOut('fast');
		  $('#' + id).fadeIn('slow');
		  $('.top-link').removeClass('hide');
		}
	}
	$(".toggle-dr-terry").click(function(){
	    toggleInfoContent('terry-dischinger');
	    return false;
	});
	
	$(".toggle-dr-bill").click(function(){
	    toggleInfoContent('bill-dischinger');
	    return false;
	});

	$(".toggle-braces").click(function(){
	    toggleInfoContent('parts-of-braces');
	    return false;
	});

	$(".toggle-procedures").click(function(){
	    toggleInfoContent('orthodontic-procedures');
	    return false;
	});
	
	$(".toggle-front-office").click(function(){
	    toggleInfoContent('front-office');
	    return false;
	});
	
	$(".toggle-lab-technicians").click(function(){
	    toggleInfoContent('lab-technicians');
	    return false;
	});
	
	$(".toggle-ortho-assistants").click(function(){
	    toggleInfoContent('ortho-assistants');
	    return false;
	});
	
	$(".toggle-treatment-coordinators").click(function(){
	    toggleInfoContent('treatment-coordinators');
	    return false;
	});
	
	//$(".toggle-anatomy").click(function(){
	//    toggleInfoContent('anatomy-of-a-tooth');
	//    return false;
	//});
	
	//Teeth for life
	//$(".toggle-teeth").click(function(){
	//    toggleInfoContent('flash-know-your-teeth');
	//    return false;
	//});
	
	//------


//Tour Slideshows
//---------------------------------------------------------------------------------

	//Slideshows
	//--- requires: 
	//--- <script type="text/javascript" src="http://8.scripts.sesamehost.com/scripts/jquery.cycle.all.min.js"></script>

		$('.controls').css('display','block');//shows prev/next controls when js is enabled
		
		//sets a class to the slideshow to set dimensions
		$('.slideshow-wrapper, .caption').addClass('jq');
		
		//slideshows
		$(function() {	
		    $('#tour-slideshow').cycle({
		        fx:     'blindY',
		        speed:   'slow',
		        timeout: 0,
		        next:   '#tour-next',
		        prev:   '#tour-prev',
		        pause:  'true',
		       	before: function() {  
		            $('#tour-caption').html(this.alt).css('display','none'); 
		        },
		       	after: function() {  
		            $('#tour-caption').html(this.alt).fadeIn('fast'); 
		        }
		    });
		});

// Standard Flash Modules
//-------------------------------------------------------------------------------

	//--- requires
	//--- <script type="text/javascript" src="http://2.scripts.sesamehost.com/scripts/jquery.flash.js"></script>
	
	// Define the default configuation values
	// followed by individual module configuration.
	// Values for individual modules will override the defaults
	var flashModules = {
		
		defaults: {			
			width: 500,
			height: 300,
			wmode: 'transparent',
			flashvars: {
				autoPlay: 'false', // change value to 'true'to play on start
				thisColor: '0x' + '271a06' // change global hex color (default=639CCE)
			},
			pluginOptions: {version: 9}
		},
	
	modules: [
	  // Define the configuration values for each flash module.
	  // Change item values in any 'flashvars' section to false to omit,
	  // Add any value to override the default value in flashModuleDefaults.
	  
	  {name: 'home', config: {width:468, height:279}},
	  {name: 'braces-diagram', config: {height: 375}},
	  {name: 'brace-painter', config: {height: 430, wmode:'opaque'}},
	  
	  	
	  {name: 'brushing-and-flossing-ortho',
	    config: {
	      flashvars: {
	        brushing: 'true',
	        flossing: 'true'
	      }
	    }
	  },
	  {name: 'brushing-and-flossing-dental',
	    config: {
	      flashvars: {
	        brushing: 'true',
	        flossing: 'true'
	      }
	    }
	  },
	  
	  {name: 'color-your-retainer', config: {width: 300, height: 300}},
	  
	  {name: 'common-treatments',
	    config: {
	      flashvars: {
	        crowding: 'true',
	        openbite: 'true',
	        deepOverbite: 'true',
	        missing: 'true',
	        underbite: 'true',
	        spacing: 'true',
	        overbite: 'true',
	        nonBraces: 'true',
	        phaseI: 'true'
	      }
	    }
	  },
	  
	  {name: 'the-damon-system-comparison', config: {width:250, height:165, wmode:'opaque'}},
	  
	  {name: 'emergency-care',
	    config: {
	      flashvars: {
	        pokingWire: 'true',
	        bracket: 'true',
	        looseWire: 'true',
	        appliance: 'true',
	        headgear: 'true',
	        soreness: 'true'
	      }
	    }
	  },
	  
	  {name: 'ibraces-logo', config: {width:200, height:135, wmode:'opaque'}},
	  
	  {name: 'know-your-teeth', config: {width:500, height:400}},
	  
	  {name: 'office-tour',
	    config: {width:500, height:375, wmode:'opaque',
		  flashvars: { 
			caption01: '',
			caption02: 'Entry way',
			caption03: 'Reception area',
			caption04: 'Coffee tables and chairs',
			caption05: 'Coffee bar',
			caption06: 'Family waiting room',
			caption07: 'Adult waiting room',
			caption08: 'Game room',
			caption09: 'Exam and consultation room',		  
			caption10: 'Records room',		  
			caption11: 'X-ray room',
			caption12: 'Sterilization area',
			caption13: 'Brushing area',
			caption14: 'Open treatment bay',
			caption15: '',
			caption16: ''		  
	      }	  
	    }
	  },
	
	  {name: 'palatal-expander', config: {width: 200, height: 150}},
	  {name: 'patient-care', config: {height: 375}},

		{name: 'smile-gallery',
	    config: {
	      flashvars: {
	        bonding: "true",
	        bridges: "true",
	        crowns: "true",
	        fillings: "true",
	        implants: "true",
	        invisalign: "true",
	        veneers: "true",
	        whitening: "true"
	      }
	    }
	  },
	  
	  {name: 'types-of-appliances',
	    config: {
	      flashvars: {
	        elastics: 'true',
	        headgear: 'true',
	        herbst: 'true',
	        palatal: 'true',
	        positioners: 'true',
	        separators: 'true'
	      }
	    }
	  },
	  
	  {name: 'types-of-braces',
	    config: {
	      flashvars: {
	        metal: 'true',
	        gold: 'false',
	        ceramic: 'true',
	        invisible: 'true',
	        lingual: 'true'
	      }
	    }
	  }
	]
	};
	
	// Loop through the defined modules 
	// and do flash replacement for any that are on the current page
	for (var j = flashModules.modules.length - 1; j >= 0; j--){
		var module = flashModules.modules[j];
		// combine default config settings with individual module config settings
		var modConfig = $.extend({}, flashModules.defaults, module.config);
		// combine default flashvars with module flashvars
		modConfig.flashvars = $.extend({}, flashModules.defaults.flashvars, module.config.flashvars);
		modConfig.src = 'flash/' + module.name + '.swf';
		$('#flash-' + module.name).flash(modConfig, flashModules.defaults.pluginOptions);
	}

// Flash Video functions
//-------------------------------------------------------------------------------

var flashVideos = {
	
		defaults: {
		  // Define the configuation values applied to each module.
		  // Each module in flashModules can override these values.
		  
		  src: 'video/flvPlayer.swf',
		   dir: 'http://media.sesamehost.com/video/',//location of video and image files
		  width: 320,
		  height: 266, // Must add 26px to height to accomodate for the UI controls
		  wmode: 'transparent',
		  menu: false,
		  allowFullScreen: true,
		  flashvars: {
		    autoStart: "false", // change value to true to play on start
		    showScaleModes: "false", //set to false to disable scale modes menu
		    smoothVideo: "true", //set to false to disable video smoothing 
		  	hiddenGui: "false"
			},
		  pluginOptions: {version: 9}
		},
	
		videos: [
			{name: 'the-damon-system',config:{width: 240, height: 206}},
			{name: 'the-damon-system-2',config:{width: 400, height: 330}},
			{name: 'in-ovation',config:{}},
			{name: 'ibraces-1',config:{}},
			{name: 'ibraces-2', config: {width: 352}},
			{name: 'ibraces-3', config: {width: 352}},
			{name: 'invisalign', config: {width: 360}},{name: 'invisalign',config:{width: 360}},
			{name: 'opalescense', config: {width: 400, height: 251}},
			{name: 'invisalign-best-friends', config: {width: 320, height: 206}},
			{name: 'invisalign-news-travels-fast', config: {width: 320, height: 206}},
			{name: 'invisalign-lobby', config:{}},
			{name: 'suresmile-01', config: {height: 206}}
		]
	};
	for (var j=0; j < flashVideos.videos.length; j++) {
						var video = flashVideos.videos[j];
						// combine default config settings with module config settings
						var vidConfig = $.extend({}, flashVideos.defaults, video.config);
						// combine default flashvars with module flashvars
						vidConfig.flashvars = $.extend({}, flashVideos.defaults.flashvars, video.config.flashvars);
						vidConfig.flashvars.flvToPlay = vidConfig.dir + video.name + '.flv';
						vidConfig.flashvars.startImage = vidConfig.dir + video.name + '.jpg';
						$('#video-' + video.name).flash(vidConfig, flashVideos.defaults.pluginOptions);
	};

// jQuery Cycle Before and After //-------------------------------------------------
$('#before-after-cycle') // Give this ID a unique name if more than one office tour is needed on a page
.before('<div class="before-after-nav">') // Ditto for this ID
.cycle({
cleartype: true, // true if clearType corrections should be applied (for IE)
cleartypeNoBg: true, // Set to true to disable extra cleartype fixing (leave false to force background color setting on slides)
speed: 500, // This controls speed of transition
timeout: 0, // This controls delay between slides. Set to 0 if more than one office tour on a page, so they don't auto-play
pager: '.before-after-nav',
before: function() {
$('.cycle-detail span').fadeOut(); // Give this ID a unique name if more than one office tour is needed on a page
},
after: function(curr, next, opts) {
var cycle_alt = $(next).find('img').attr('alt'); // This grabs the image alt text
$('.cycle-detail span').html(cycle_alt).fadeIn(); // This puts alt text into the caption span
}
}); 


// Game room
//-------------------------------------------------------------------------------
	
	// list the games that we want activated on click
	var games = Array('asteroids', 'frogger', 'pong', 'simon', 'snake', 'space-invaders', 'tetris', 'tic-tac-toe');
	
	// set the click behavior for a game link
	var setGameClick = function(game){
	$("a." + game).click(function(){
	  $('#sesame-game').flash(  // #sesame-game is the empty div that will contain the active game
	    {
	    src: 'games/' + game + '.swf',
	    width: 400,
	    height: 300,
	    wmode: 'transparent'
	    },
	    { version: 8 }
	  );
	});
	};
	
	// loop through the games array and
	// set the click behavior for each game link
	for (var j=0; j<games.length; j++){
	setGameClick(games[j]);
	};

//Basic HTML functions
//---------------------------------------------------------------------------------

	// add 'back to top' link when the content is taller than the window
	// this has to be done after flash replacement because the content height changes
	//-- requires: <p class="top-link hide"><a href="#container">Back to top &uarr;</a></p> just before the closing content tag
	//-- requires .hide {display: none;} is css
	if ($('#content-body').height() > $(window).height()) {
		$('.top-link').removeClass('hide');
	}
	
	// Open external links in new windows
	$('a[href^="http://"]').not('[href*="orthosesame.com"]').addClass('external').attr('target', '_blank');
	
	// Open pdf links in new windows + add icon
	$('a[href$=".pdf"]').not('[class*="noicon"]').parent().append('<span/>').addClass('pdf').attr('target', '_blank');

	// add icons to links which open in prettyPhoto
	$("a[rel^='prettyPhoto[flash]']").parent('li').append('<span/>').addClass('video-link');

 
	//Ordered List Style

	$('ol.alpha, ol.numeric').addClass('js');
	$("ol li").each(function (i) {
	    $(this).wrapInner('<span/>');
    });

	//fancy quotes
	//--- required styles
	//--- q:before, q:after {/* remove quotes since IE doesn't understand :( */
	//---    content: ""; 
	//--- }
	//--- q {font-style: oblique;}
	//--- q.js span {font: 22px Georgia; color: #802c11; line-height: 18px; vertical-align: middle;}
	$('q').addClass('js');
	$('q').each( function (i) {
		$(this).prepend('<span>&ldquo;</span>').append(' <span>&rdquo;</span>');
	});

	
	//image preview tooltips
	imagePreview();
	
	

		//PrettyPhoto modal windows
//---------------------------------------------------------------------------------
$("a[rel^='prettyPhoto']").prettyPhoto({
animationSpeed: 'normal', /* fast/slow/normal */
default_width: 900,
default_height: 700,
opacity: 0.65, /* Value betwee 0 and 1 */
showTitle: false, /* true/false */
allowresize: true, /* true/false */
counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
wmode: 'transparent', /* Set the flash wmode attribute */
autoplay: true, /* Automatically start videos: True/False */
modal: false /* If set to true, only the close button will close the window */
}); 

//Form Functions
//---------------------------------------------------------------------------------
	
	//toggle hidden field on Appointment Request Form
	$('#Found').change(function() {
		var selected = $('#Found option:selected');
		if(selected.val() == 'Other') {
			$('#found-other').toggle();
		} else {
			$('#found-other').hide();
		}
	});  
	
	//clear form fields with "clearme" class when clicked
	$('.clearme').one("focus", function() {
			$(this).val("");
	});


//Form validation
//---------------------------------------------------------------------------------
	
	//--- requires: 
	//--- <script type="text/javascript" src="http://6.scripts.sesamehost.com/scripts/jquery.validate.js"></script>
	//--- <script type="text/javascript" src="http://7.scripts.sesamehost.com/scripts/jquery.maskedinput-1.2.2.min.js"></script>

	//masked input
	$(".date-mask").mask("99/99/9999");
	$(".phone-mask").mask("(999) 999-9999");

	//additional validation methods
	$.validator.addMethod("phone", function(phone_number, element) {
	    phone_number = phone_number.replace(/\s+/g, ""); 
		return this.optional(element) || phone_number.length > 9 &&
			phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
	}, "Please specify a valid phone number");

	//validator
	$(".validate").each(function() {
		$(this).validate({
			errorElement: "div",
				success: function(label) {
					label.text("ok!").addClass("success");
				},
			rules: {
				Name: {
					required:true,
					minlength: 5
				},
				Doctor_Name: {
					required:true,
					minlength: 5
				},
				Patient_Name: {
					required:true,
					minlength: 5
				},
				Patient_Email: {
					required: true,
					email:true
				},
				Patient_Patient_Referring: {
					required:true,
					minlength: 5
				},
				Doctor_Patient_Referring: {
					required:true,
					minlength: 5
				},
				Doctor_Email: {
					required: true,
					email:true
				},
				Appointment_Email: {
					required: true,
					email:true
				},
				Email: {
					email:true
				},
				Daytime_Phone: {
					required: true,
					phone: true	
				},
				Patient_Phone: {
					required: true,
					phone: true	
				},
				Message: {
					required:true,
					minlength: 12
				},
				Would_like_to: {
					required: true
				},
				User_Name: {
					required: true
				},
				Password: {
					required: true
				},
				txtNumber: {
					required:true,
					minlength: 5
				}
			}
		});
	});

});//end document.ready