$(document).ready(function () {
	
	
	
	
	//clear me function
			 var clearMePrevious = '';					
				
			// clear input on focus
			$(".clearMeFocus").focus(function()      
			{
			if($(this).val()==$(this).attr("title")) 
			{
			clearMePrevious = $(this).val();    
			$(this).val('');							
			}
			});
			
			// if field is empty afterward, add text again      
			$(".clearMeFocus").blur(function()            
			{
			if($(this).val()=="")               
			{
			$(this).val(clearMePrevious);       
			}
			});
	  
	 	//new truncate
	  $('.bioDesc p').truncatable({	limit: 200, more: '<br>Read More »', less: true, hideText: '&nbsp;« Less' }); 
	  $('.partDesc p').truncatable({	limit: 170, more: '<br>Read More »', less: true, hideText: '&nbsp;« Less' }); 

	  
	  
	  //accordian
	  $( "#accordion" ).accordion({
			active:false,
			autoHeight: false,
			collapsible: true
		});
		
	$( "#landing-accordion" ).accordion({
			collapsible: false,
			autoHeight:false,
			active: 1
		});
		

		
		//add callout randomly if there's room under the nav
		var content = $('#content').height();
		var sidebar = $('#side_nav').height();
		var diff = (content - sidebar);
		
		var randomN= Math.floor(Math.random()*4);
		
		var path = '<img src="/Images/callout/ad' + randomN + '.png">';
		
		switch(randomN)
			{
			case 0:
			  var snippet = '<blockquote>DataComm is a relationship driven company. We approach each challenge and opportunity with a unique level of commitment and consid­eration for our customers\' long­term benefit.<br><br><strong>Bruce C. Boyer</strong><br>Co-Founder</blockquote>';
			  break;
			case 1:
			  var snippet = '<blockquote>DataComm is always striving to find simple solutions to difficult problems and then offering those solutions to our customers.<br><br><strong>Miguel Rosado</strong><br>Purchasing & Production Supervisor</blockquote>';
			  break;
		    case 2:
			   var snippet = '<blockquote>We have never said, "that is how it has always been done." This mindset has generated 23+ years of success.<br><br><strong>Don Steele</strong><br>Senior Accounts Manager</blockquote>';
			  break;
			case 3:
			   var snippet = '<blockquote>Our business is about technology, yes. But it\'s also about operations and customer relationships..<br><br><strong>Nancy Kimmel</strong><br>Accounting and Human Resources</blockquote>';
			  break;

			}
			
			if (diff > 400) {
			$('#callout').html(path + snippet);
			}



	  //image preview zoom
		$("a[rel='pop']").colorbox();

		//icontact		
		
		if (getUrlVars()["message"])  {
			if (getUrlVars()["message"] == 'success') { 
				var finalMessage = '<p><img src="/Images/success.jpg">Thanks! You have been added to our email list successfully.</p>'}
				
			if (getUrlVars()["message"] == 'failure') { var finalMessage = '<p><img src="/Images/error.jpg">Sorry, Not a valid email - please try again.</p>'}
				
				//show colorbox with results inside
				$('#results').html(finalMessage).show();
				$.fn.colorbox({'href':'#results', 'open':true, 'inline':true, 'width':'500px', 'height':'200px'});
				$().bind('cbox_closed', function(){
				$('#results').hide();
		});	
		}
		

		function getUrlVars()
		{
			var vars = [], hash;
			var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
			for(var i = 0; i < hashes.length; i++)
			{
				hash = hashes[i].split('=');
				vars.push(hash[0]);
				vars[hash[0]] = hash[1];
			}
			return vars;
		}

	 //videoplayer
/*	 	 jwplayer("mainVideo").setup({ flashplayer: "/wp-content/themes/dcn/js/libs/player.swf", 
		 file: "/wp-content/themes/dcn/media/shoretel_vid.mp4",
		  height: 630,
		   width: 354,
		   'image': '/wp-content/themes/dcn/images/main_shoretel_vid.jpg'
			 });	*/

	 //mainnav parent a hovers stay up on ul hover
	 $(".secondTier").hover(
		  function () {
			$(this).parent().addClass('current');
		  }, 
		  function () {
			$(this).parent().removeClass('current');
		  }
		);
	
	//print friendly window

                $('.printLink').click(function(){

					window.print();
					
					return false;

                });

	  //ip telephony wheel function
	   
		  //init
		  var strippedID = 'plan';
		  var currentID = 'plan';
		  $('#plan-wheel').addClass('planOver');
		  $('#plan-nav').addClass('navOn');
		  $('#plan-text').show();
		  
		  //click events
		  $('#wheel a').click(function(){
			  var clickID = $(this).attr('id');
			  //trim it
			  var splitID = clickID.split("-");
			  var strippedID = splitID[0];
	
			  //hide current navs and text
			  $('#'+ currentID + '-wheel').removeClass(currentID + 'Over');
			  $('#'+ currentID + '-nav').removeClass('navOn');
			  $('#'+ currentID + '-text').hide();
			  //show new stuff
			  $('#'+strippedID+'-wheel').addClass(strippedID+'Over');
			  $('#'+strippedID+'-nav').addClass('navOn');
			  $('#'+strippedID + '-text').show();
			  
			  //reset currentID
				currentID = strippedID;
				return false;
		  });
		  

	  
}); //end on ready


