$(document).ready(function () {
	
	
		// Add print header to top of page
		$("body").prepend("<h5 class=\"print\"><img src=\"/templateFiles/images/logo_cstech.png\" /></h5>"); 
// Add print footer to bottom of page
		    $("body").after("<h6 class=\"print\"><strong>Cornerstone Technologies</strong><br />Phone: (403) 668-5533 | Level 29, First Canadian Centre 350 - 7th Avenue SW Calgary, Alberta  T2P 3N9 Canada</h5>"); 
//font replacement
  Cufon.replace('h1')('h1 a')('h2')('h3')('h4')('h5')('h6')('p.statement')('#sub-nav a')('#nav ul li a', {
    hover: true
  })

  //add flash to home page
  if ($('#banner').length) {
    $('#banner').flash({
      src: 'cu3er.swf',
      width: 960,
      height: 360,
      wmode: "transparent"
    }); 
}

  //for top navigation
  $(" #nav ul ul ").css({
    display: "none"
  }); 
// Opera Fix
  $(" #nav li").hover(function () {
    $(this).find('ul:first').css({
      visibility: "visible",
      display: "none"
    }).slideDown(400); 
}, function () {
    $(this).find('ul:first').css({
      visibility: "hidden"
    }); 
}); 
//scrollable in porfolio
  if ($('#browsable').length) {
    $("#browsable").scrollable().navigator(); 
}


//scrollable in client list
if ($('#client-list').length) {
	$("#list").scrollable({circular: true, mousewheel: false}).navigator().autoscroll({
	interval: 5000
	}); 
}

	//scrollable in partner list
	if ($('#partner-list').length) {
		$("#list").scrollable({circular: true, mousewheel: false}).navigator().autoscroll({
		interval: 5000
		}); 
}


  //email spam protection
  $('.email').each(function () {
    var $email = $(this); 
var address = $email.text().replace(/\s*\[at\]\s*/, '@').replace(/\s*\[dot\]\s*/g, '.'); 
$email.html('<a href="mailto:' + address + '">' + address + '</a>'); 
});
  
  
/* Portfolio SeekTo */

//Check if Projects exist

if($('.projects .project').length > 1){
	
	var CurrentURL = document.URL;
	var CurrentURLLength = CurrentURL.length;
	
	//Check if there is a query string.
	if(CurrentURL.indexOf('?p=') > -1){			
		//Find Value Length
		var PageURlLength = CurrentURL.indexOf('?p=') + 3;
		var Value = CurrentURL.substring(PageURlLength, CurrentURLLength);
		//Find where the selected project is in the queue.
		var Position = 0;
		$('.projects div').each(function(index){						  
			if($('.projects div:eq(' + index + ')').attr('id') == Value){
				Position = (index);
			}
		});
		//Remove the first project nav class.
		$('.navi .active').removeClass('active');
		//Add the active class to the selected project.
		$('.navi a:eq(' + Position + ')').addClass('active');
		var LeftValue = 588 * Position;
		//Animate portfolio slide to the left.
		$('.projects').animate({
			left: '-' + LeftValue + 'px'
		}, 500);
	}
}

}); 
