// document is loaded
jQuery(document).ready(function($){
	
	// main nav
	/*$("#menu > ul").superfish({
		delay:900,
		autoArrows: false,
		animation:{height:"show"}
	});*/	
	
	// keep main menu items from jumping
	$('#nav a[href="#"]').click(function() { return false });
	
	// remove outline from links
	$('a').focus(function() { this.blur(); });
	
	// adding some classes to the menus
	$('li:first', 'ul.Level1').addClass('first');
	$('li:last', 'ul.Level1').addClass('last');
	
	// open off-site links in new window
	$("a[href^='http']:not([href*='goodortho.com'])").each(function() {
		$(this).attr("target", "_blank");
	});
	// for pdfs
	$("a[href$='.pdf']").attr("target","_blank");
	
	// home page "flash"
	if ($('#flash-home').length) {
		$('#flash-home .pics').cycle();	
	}
	
	$("a.fancy").fancybox({
		'frameWidth'	:	400,
		'frameHeight'	:	300,
		'callbackOnClose': function() { $("#fancy_content").empty(); },
		'hideOnContentClick': false
	});
	
	// for IE, as usual
	if (location.hash) {
		var hash = location.hash;		
		var pos = $(hash).offset();
		window.scrollTo(pos.left,pos.top);
	}
	
	// faq accordions
	$('.acc-faq h3').click(function() {
		$(this).toggleClass('active').next().toggle();
	});
	$('.acc-faq h3').hover(function() {
		$(this).toggleClass('hover');	
	});
	
	// gum disease FF
	$('.gumFF').flashembed('http://tools.televoxsites.com/features/gums.swf');
	// rpe
	if ($('.rpeFF').length) {
		$('.rpeFF').click(function() {
			$(this).flashembed({src: 'http://tools.televoxsites.com/features/rpa2.swf', wmode:'transparent'});	
		});
	}
	// orthognathic surgery
	$('#jawFF').flashembed('http://tools.televoxsites.com/features/jaws.swf');
	
	// slideshows
	// Slideshow
	$('#slideshow-manhattan').cycle({ 
		delay:  3000, 
		speed:  500, 
		prev:   '#previous-manhattan', 
		next:   '#next-manhattan', 
		before: onBefore1
	}); 
	
	function onBefore1() { 
		$('#title-manhattan').html(this.alt); 
	};
	
	$('#slideshow-riverdale').cycle({ 
		delay:  3000, 
		speed:  500, 
		prev:   '#previous-riverdale', 
		next:   '#next-riverdale', 
		before: onBefore2
	}); 
	
	function onBefore2() { 
		$('#title-riverdale').html(this.alt); 
	};
	
	if ($('body #content').height() > $(window).height()) {
		$('#content').append('<p class="top-link"><a href="#">Back to top &uarr;</a></p>');
	}
	
	if ($('#simplegallery').length) {
		var myText = [
			"18 months of braces with Suresmile",
			"18 months of Invisalign", 
			"18 months of Invisalign",
			"Maxillary expander and 19 months of braces",
			"Maxillary expander and 24 months of braces",
			"16 months of braces",
			"16 months of braces"
		]
	
		var mygallery1 = new simpleGallery({
			wrapperid: "simplegallery", //ID of main gallery container,
			dimensions: [444, 404], //width/height of gallery in pixels. Should reflect dimensions of the images exactly
			imagearray: [
				[skinpath+"images/before-after/1.jpg", "", "", ""],
				[skinpath+"images/before-after/2.jpg", "", "", ""],
				[skinpath+"images/before-after/3.jpg", "", "", ""],
				[skinpath+"images/before-after/4.jpg", "", "", ""],
				[skinpath+"images/before-after/5.jpg", "", "", ""],
				[skinpath+"images/before-after/6.jpg", "", "", ""],
				[skinpath+"images/before-after/7.jpg", "", "", ""]  	  	  	  	  	  	  	  
			],
			autoplay: [true, 2500, 2], //[auto_play_boolean, delay_btw_slide_millisec, cycles_before_stopping_int]
			persist: true,
			fadeduration: 500, //transition duration (milliseconds)
			oninit:function(){ //event that fires when gallery has initialized/ ready to run
				//Keyword "this": references current gallery instance (ie: try this.navigate("play/pause")
			},
			onslide:function(curslide, i){ //event that fires after each slide is shown
				document.getElementById("textBox").innerHTML=myText[i]
				//Keyword "this": references current gallery instance
				//curslide: returns DOM reference to current slide's DIV (ie: try alert(curslide.innerHTML)
				//i: integer reflecting current image within collection being shown (0=1st image, 1=2nd etc)
			}
		});
	}
	
	$('#video-in-ovation').flashembed(skinpath+'video/flowplayer-3.2.7.swf', {
		config: {
			plugins: { controls: { url: 'flowplayer.controls-3.2.5.swf' } },
			clip: { autoPlay: false, autoBuffering: true, url: skinpath+'video/in-ovation.flv' }
		}
	});
	
	$('#video-suresmile').flashembed(skinpath+'video/flowplayer-3.2.7.swf', {
		config: {
			plugins: { controls: { url: 'flowplayer.controls-3.2.5.swf' } },
			clip: { autoPlay: false, autoBuffering: true, url: skinpath+'video/suresmile.flv' }
		}
	});
	
	$('#video-suresmile-2').flashembed(skinpath+'video/flowplayer-3.2.7.swf', {
		config: {
			plugins: { controls: { url: 'flowplayer.controls-3.2.5.swf' } },
			clip: { autoPlay: false, autoBuffering: true, url: skinpath+'video/suresmile-2.flv' }
		}
	});
	
	$('#invisalign-video').flashembed(skinpath+'video/flowplayer-3.2.7.swf', {
		config: {
			plugins: { controls: { url: 'flowplayer.controls-3.2.5.swf' } },
			clip: { autoPlay: false, autoBuffering: true, url: skinpath+'video/invisalign.flv' }
		}
	});
	
	//fancybox
	$("a.fancy-invisalign-patients").fancybox({ 
		'overlayOpacity': .5,
 		'overlayShow': true,
 		'hideOnContentClick': false,
		'frameWidth': 520,
      'frameHeight': 383
 	});
	
	$('.accordion-faq h3').click(function() {
		$(this).toggleClass('active').next().toggle();
		return false;
	});
	$('.accordion-faq h3').hover(function() {
		$(this).toggleClass('hover');
	});
	
	$('.patient-referral').click(function() {
		$('.DnnModule-445').show();
		$('.DnnModule-446').hide();
		return false;
	});
	
	$('.doctor-referral').click(function() {
		$('.DnnModule-446').show();
		$('.DnnModule-445').hide();
		return false;
	});
	

});

//sIFR implementation
// DIE!!!!!!!!!!!!!!!!!!
function runSIFR(){
	var lci = {  src: skinpath + 'flash/LucidaCalligraphy.swf' };
	sIFR.activate(lci);
	sIFR.replace(lci, {
	  selector: 'h1', 
	  wmode: 'transparent', 
	  src:  skinpath +  'flash/LucidaCalligraphy.swf', 
	  css: [ '.sIFR-root {color:#ffffff; font-size:32px;}'  ]
	});
}
