$(function(){
	/******** STANDARD SYNCSHOW BLOCK **********/
	//INJECT THE DATE INTO THE FOOTER
	var d=new Date();
    $("#currentYear").html( d.getFullYear() );
    //NYROMODAL LIVE UPDATING FOR FUTURE DOM OBJECTS
    $('.nyroModal').die('mouseover').live('mouseover',function(){ $(this).nyroModal(); });
    //USE "sstip" CLASS TO DISPLAY TOOL TIP OFF TITLE ATTR
    //$(".sstip").die('mouseover').live('mouseover',function(){ $(".aToolTip").remove(); $(this).aToolTip().mouseover(); });
	$(".sectionContent").attr("style", "display: none;");
	$(".sectionContent:first").attr("style", "");
	$(".sectionTitle").click(function(event){ if(!$(this).hasClass("fullContent")){ $(".sectionContent").slideUp("normal"); $(".sectionTitle").removeClass("fullContent"); $(this).toggleClass("fullContent"); $(".sectionContent", this).slideDown("normal"); } });
	/******** END SYNCSHOW BLOCK **********/
	
	$(".sstip").removeClass(".sstip");
    
    /** IE6 HACK **/
    if($.browser.msie && $.browser.version < 7){ $("#MainNav a").css("display","inline"); }
    
    /** THIS IS NEEDED TO RESIZE/REPOSITION THE MainNav **/
    var MainNavHeight = $("#MainNav").outerHeight();
    $("#MainNavSpacer").height( MainNavHeight );
    $("#blogMainNav").css("bottom",(MainNavHeight+30));
    //if( $(".syncshow").is("div") && $("#HomeMainNav").is("div") ) $('#MainNav').appendTo('#MainNavSpacer');

    /*** BG PHOTO INFO ***/
    $("#ieibginfo,#iei_photo_button a").click(function(e){
    	e.preventDefault();
    	if(!$(this).hasClass('open')){
	    	//OPEN
	    	$("#ieicontainer").fadeOut("normal",function(){
	    		//display caption
	    		clearTimeout(to);
	    		$("#ieibginfo div.photoInstr").toggle("fast");
	    		$("#bgcaption").stop().show().animate( {width:"1010px",left:"0px"}, {queue:false, duration:400, complete:function(){
	    			$(this).children("div.inCaption").slideDown();
	    			$("#bginfo-return").fadeIn();
	    		}});
	    	});
	    	$("#ieibginfo").addClass('open');
    	}
    	else{
    		//CLOSE
    		$("#bginfo-return").fadeOut();
	    	$("#bgcaption div.inCaption").slideUp("normal",function(){
	    		//hide caption
	    		$("#ieibginfo div.photoInstr").toggle("fast");
	    		$("#bgcaption").stop().animate( {width:"0px",left:"1010px"}, {queue:false, duration:400, complete:function(){
	    			$(this).hide();
	    			$("#ieicontainer").fadeIn();
	    			rotateClientLogos();
	    		}});
	    	});
	    	$("#ieibginfo").removeClass('open');
    	}
    });//end click
    $("#bgcaption,#bginfo-return").click(function(e){
    	//CLOSE
    	e.preventDefault();
    	$("#bginfo-return").fadeOut();
    	$("#bgcaption div.inCaption").slideUp("normal",function(){
    		//hide caption
    		$("#ieibginfo div.photoInstr").toggle("fast");
    		$("#bgcaption").stop().animate( {width:"0px",left:"1010px"}, {queue:false, duration:400, complete:function(){
    			$(this).hide();
    			$("#ieicontainer").fadeIn();
    			rotateClientLogos();
    		}});
    	});
    	$("#ieibginfo").removeClass('open');
    });
    $(".bginfo").hover(function(){
    	clearTimeout( toPhoto );
    	$(".photoWord").stop().animate( {width:"26px"}, {queue:false, duration:400} );
    },function(){
    	clearTimeout( toPhoto );
    	$(".photoWord").stop().animate( {width:"16px"}, {queue:false, duration:400} );
    });
    toPhoto = setTimeout("bounce_photo_button()", 5000);
    /*** END BG PHOTO CAPTION ***/
    
    
    /*** CONTACT US FORM ON RIGHT SIDE ***/
    $('.consultantlink').click(function(e){
    	e.preventDefault();
        var minheight = 140, maxheight = 340, easingspeed = 500, $consultantform = $('.consultantform');
        if ( $consultantform.hasClass('cf-close') ){
          $('.speakconsultant').animate({ height: maxheight+'px' }, easingspeed );
          $consultantform.fadeIn("slow").removeClass('cf-close').addClass('cf-open');
        } 
        else if( $consultantform.hasClass('cf-open') ) {
          $('.speakconsultant').animate({ height: minheight+'px' }, easingspeed );
          $consultantform.fadeOut("slow").removeClass('cf-open').addClass('cf-close');
        }
    });

    
    /*** HOMEPAGE CLIENT LOGO ROTATION ***/
    if( $('#homeImageRotation').is("div") ){
		to = setTimeout ( "rotateClientLogos()", rotationTime );
    }
    /*** END HOMEPAGE CLIENT LOGO ROTATION ***/
    
    /** SPECIFICALLY FOR BLOG ON JQUERY CONFERENCE **/
    $("#jq-example").click(function(e){
    	e.preventDefault(); 
    	$("#iei_photo_button a").click();
    });
    
    
    /* IEI HOME ROTATOR */
    var $ieihomerotatorcontainer = $('.ieihomerotatorcontainer');
    if( $ieihomerotatorcontainer.is('div') ){ //only run on homepage
		$ieihomerotatorcontainer.cycle({
			speed: animduration,
			timeout: '5000',
			before: function(currSlideElement, nextSlideElement, options, forwardFlag){ tabmakeshort(currSlideElement); },
			after: tabmakelong,
			delay: 1000,
			pager: '#ieihomerotatornav',
			pagerEvent: 'click',
			pagerAnchorBuilder: function(idx, slide) { 
				return "<a href='#'>+</a>";
			}
		});
		tabmakelong();
		
		//var is_mobile = (navigator.userAgent.toLowerCase().indexOf('mobile')!=-1);
	
		//$('#ieihomerotatornav a').hover(function(){ $ieihomerotatorcontainer.cycle('pause'); },function(){ });
		$('#ieihomerotatornav a').click(function(){ $ieihomerotatorcontainer.cycle('pause'); flashplayer=false; });
		$('.videoposter').click(function(){
				var vidposterID = this.id.replace('homevideoposter-','');
				var vidplayerID = "homevideo-"+vidposterID;
				$ieihomerotatorcontainer.cycle('pause');
				$(this).hide();
				var is_HTML5 = $('#'+vidplayerID).is('video');
				if( is_HTML5 ) $('#'+vidplayerID).show();
				if(!$.browser.msie && is_HTML5){
					document.getElementById(vidplayerID).play();
				} else {
					var videofile = $('#homeflashvideo-'+vidposterID).attr('alt');
					$('#homeflashvideo-'+vidposterID).html("Flash Player Not Available").flash({
						swf: '/syncshow/style/images/gl_FLVplayer-NEW.swf',
						width: 608,
						height: 285,
						params: {
							play: true,
							allowScriptAccess: 'sameDomain',
							 quality: 'high',
							 bgcolor:'#000000',
							 wmode:'transparent',
							 menu:'false',
							 flashvars: {
								link: '/syncshow/style/images/homeRotator/'+videofile+'.flv',
								video: ''
							 }
						}
					});
					flashplayer = true;
				}//end else
		});//end videoposter
			
		//can this be in sty_style?
		$("#ieihomerotatornav a:eq(0)").css('background-color', '#7A0022');
		$("#ieihomerotatornav a:eq(1)").css('background-color', '#336666');
		$("#ieihomerotatornav a:eq(2)").css('background-color', '#CC6600');
		$("#ieihomerotatornav a:eq(3)").css('background-color', '#718611');
		//$("#ieihomerotatornav a:eq(4)").css('background-color', '#7A0022');
		//end home css setters
		
    }//END HOMEPAGE ROTATION
    /** END HOMEPAGE ROTATION **/
     
    
    /*SWF OBJECT PLUGIN FOR JQUERY*/
    if( $('#ieihomevideo').is('div') ){
	    $('#ieihomevideo').flash({
	    	swf: '/syncshow/style/images/homeFlash/homepageFlash-IEI_V2.swf',   
	    	height: 350,   
	    	width: 1010,
	    	wmode:'transparent',
	    	menu:'false',
	    	scale:'showall',
	    	params: {
	    		allowScriptAccess: 'sameDomain',   
	    		quality: 'high', 
	    		bgcolor:'#000000',
	    		flashvars: {   
	    			URLlink: "/WebDevDefine"
	    		}
	    	}  
	    });
    }
    
    if( $('#webDevFlash').is('div') ){
	    $('#webDevFlash').flash({
	    	swf: '/syncshow/style/images/webDevFlash/webDevFlash.swf',   
	    	width: 245,
	    	height: 370,
	    	wmode:'transparent',
	    	menu:'false',
	    	params: {   
	    		play:false, 
	    		allowScriptAccess: 'sameDomain',   
	    		quality: 'high', 
	    		bgcolor:'#FFFFFF', 
	    		scale:'showall', 
	    		flashvars: {
	    		}   
	    	}  
	    });
    }
    
    $.nyroModalSettings({ minHeight: 100, minWidth: 100 });
    
    if( $("ul.sf-menu").is('ul') ){
	    $("ul.sf-menu").supersubs({ 
	        minWidth:    12,   // minimum width of sub-menus in em units 
	        maxWidth:    27,   // maximum width of sub-menus in em units 
	        extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
	                           // due to slight rounding differences and font-family 
	    }).superfish();  // call supersubs first, then superfish, so that subs are 
	                     // not display:none when measuring. Call before initialising 
	                     // containing tabs for same reason.
    }
   
    if ( (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/Android/i)) ) {
    	$('.htmlFiveVideoPlayer').hide();
        $('#i-padLinkHomePage').show();
    };
    
    /** HOMEPAGE SLIDEPANEL **/
    /*
    $("#slidePanel").slidePanel({
    	width:'445',
    	height:'185',
    	slideWidth:'430',
    	tabWidth:'15',
    	tabHeight:'36',
    	border:'2px solid #cacaca',
    	backgroundColor:'transparent',
    	coverSlideBackgroundColor:'#eeeeee',
    	padding:'12px',
    	openIndex:'1'
    });
    */
    
});


/*** UTILITY FUNCTIONS ***/
var to; //Client Logo Timeout
var rotationTime = 5000;
var lastIndex=-1;
function rotateClientLogos(){
	var count = $('.clientLogo').length;
	if(lastIndex<0) lastIndex = $('.clientLogo:visible').last().index('.clientLogo');
	var nextIndexA = lastIndex+1;
	if(nextIndexA == count) nextIndexA = 0;
	var nextIndexB = nextIndexA+1;
	if(nextIndexB == count) nextIndexB = 0;
	var nextIndexC = nextIndexB+1;
	if(nextIndexC == count) nextIndexC = 0;
	var nextIndexD = nextIndexC+1;
	if(nextIndexD == count) nextIndexD = 0;
	lastIndex = nextIndexD;
	$('.clientLogo:visible').hide();
	$('.clientLogo:eq('+nextIndexA+')').fadeIn();
	$('.clientLogo:eq('+nextIndexB+')').fadeIn();
	$('.clientLogo:eq('+nextIndexC+')').fadeIn();
	$('.clientLogo:eq('+nextIndexD+')').fadeIn();
	to = setTimeout ( "rotateClientLogos()", rotationTime );
}
var toPhoto; //PHOTO button timeout
function bounce_photo_button(){
	$(".photoWord").stop().animate( {width:"26px"}, {queue:false, duration:500, complete:function(){
		$(".photoWord").animate( {width:"16px"}, {queue:false, duration:500, complete:function(){
			$(".photoWord").animate( {width:"26px"}, {queue:false, duration:500, complete:function(){
				$(".photoWord").animate( {width:"16px"}, {queue:false, duration:500, complete:function(){
					toPhoto = setTimeout("bounce_photo_button()", 30000);
				}});
			}});
		}});
	}});
}
function addbookmark() {
	if ( navigator.appName != 'Microsoft Internet Explorer')
		window.sidebar.addPanel(document.title,document.URL,"");
	else
		window.external.AddFavorite(document.URL,document.title);
}

/** HOME ROTATOR FUNCTIONS **/
var animduration = 500;
var tabchangeamt = 10;
var flashplayer = false;
function tabmakeshort(currSlideElement){
	//before slide change
	var $curSlide = $(currSlideElement);
	if( $curSlide.find('.homerotatorvid').is('div') ){ //slide has video?
		var $html5Video = $curSlide.find('video');
		var $flashVideo = $curSlide.find('.homeflashvideo');
		if( $html5Video.is(':visible') || flashplayer==true ){ //slide video is visible?
			var $videoPoster = $curSlide.find('.videoposter');
			if( $html5Video.is(':visible') ){
				var videoID = $html5Video.attr('id');
				document.getElementById(videoID).pause();
				$html5Video.hide();
			}else{
				//stop flash video player by clearing out the div
				$flashVideo.html('');
			}
			$videoPoster.fadeIn();
		}//else no video
	}
	$('.activeSlide').animate( { paddingTop: '-='+tabchangeamt }, {duration: animduration} );
}
function tabmakelong(){
	//after slide change
	$('.activeSlide').animate( { paddingTop: '+='+tabchangeamt }, {duration: animduration} );
}
function videoOnEnded(domVideo){
	var videoID = domVideo.id;
	var posterID = videoID.replace('homevideo','homevideoposter');
	$("#"+videoID).hide();
	$("#"+posterID).fadeIn();
	$('.ieihomerotatorcontainer').cycle('resume');
}
/** END HOME ROTATOR FUNCTIONS **/


