$(function(){
	
         

	
	var pageURL = window.location.pathname;
	var rootURL = "http://msd2011.brinnmarketing.com";
	//alert(pageURL);
		
	// Styleswitcher
	
		//if(!$.cookie('visits')){
//     $.cookie('visits',0, {expires: 30, path: '/'});
//   }
//   
//if(!$.cookie('last') || parseInt($.cookie('last'))+600000<new Date().getTime()) // 10minutes expired, new visit
//
//$.cookie('visits', (parseInt($.cookie('visits')) + 1), {expires: 30, path: '/'}) 
//   //will expire after 30 days
//   $.cookie('last',new Date().getTime(),{expires: 1});
//   
//   if(parseInt($.cookie('visits')) == 2){
//    $('body').removeClass().addClass('blue');  
//   } else if (parseInt($.cookie('visits')) == 3){
//    $('body').removeClass().addClass('green');  
//   } else if (parseInt($.cookie('visits')) == 4){
//    $('body').removeClass().addClass('purple');  
//   } else if (parseInt($.cookie('visits')) == 5){
//    $('body').removeClass().addClass('red');  
//   } else if (parseInt($.cookie('visits')) > 5){
//    $.cookie('visits', 1);               
//};


	
		  var pageColour = $('body').attr('class');
				  
				  if (pageColour === "yellow") {
				  var linkColour = "#F5B418"
			  } else if (pageColour === "blue") {
				  var linkColour = "#73acde"
			  } else if (pageColour === "green") {
				  var linkColour = "#c4db0d"
			  } else if (pageColour === "purple") {
				  var linkColour = "#b085b2"
			  } else if (pageColour === "red") {
				  var linkColour = "#9b1d2e"
			  }
			  
			 

			  
			  // Capability Hovers
		
				   if (pageColour === "yellow") {
			$(".capbox").hover(
		  
			function () {
			  $(this).children("a.icon").css("background-position", "0 -120px");
			}, function () {
			  $(this).children("a.icon").css("background-position", "0 0px");
			});
		  
		  } else if (pageColour === "blue") {
			$(".capbox").hover(
		  
			function () {
			  $(this).children("a.icon").css("background-position", "0 -240px");
			}, function () {
			  $(this).children("a.icon").css("background-position", "0 0px");
			});
		  
		  }
		  if (pageColour === "green") {
			$(".capbox").hover(
		  
			function () {
			  $(this).children("a.icon").css("background-position", "0 -360px");
			}, function () {
			  $(this).children("a.icon").css("background-position", "0 0px");
			});
		  
		  }
		  if (pageColour === "purple") {
			$(".capbox").hover(
		  
			function () {
			  $(this).children("a.icon").css("background-position", "0 -480px");
			}, function () {
			  $(this).children("a.icon").css("background-position", "0 0px");
			});
		  
		  }
		  if (pageColour === "red") {
			$(".capbox").hover(
		  
			function () {
			  $(this).children("a.icon").css("background-position", "0 -600px");
			}, function () {
			  $(this).children("a.icon").css("background-position", "0 0px");
			});
		  
		  } // end statement
			  
			 
		// Banner video
		
		
		// Detect iPad
		var isiPad = navigator.userAgent.match(/iPad/i) != null;
		
		

		
		if (pageURL === "/" || pageURL === "/banner-test.html") { // if on the homepage or banner test
		if ( $.browser.msie ) { // check if the browser is IE
		} else { // if not enable HTML5 video
	
			var v = document.getElementById("banner");
			var h = document.getElementById("holder");
			h.onclick = function () {
			  if (v.paused) {
				v.play();
			  } else {
				v.pause();
			  }
			};
			
	} //end statement
	
	
	//test banner for ie
	
	if ( $.browser.msie ) { // if the browser is IE and on the banner test page
		
		$("#holder").remove(); // remove the holder image
		//$('.banner').flash('/video/preloader-loadmovie.swf'); // load the flash swf	
		
		
		
		$('.banner').flash(
			{
				// test_flashvars.swf is the flash document
				swf: '/video/MSD-banner.swf',
				// these arguments will be passed into the flash document
				width: 940,
				height: 350,
				play: true
			}
		);
	
	} //end ie test
	
	
	
		// Click banner fade to start video or fallback		
		$('.banner').css("cursor", "pointer");
		$('.banner img').click(function(){
			$(this).fadeOut(1000);
			$('.banner-link').fadeOut(1000);
			
			});
			
		}
		
	
	// Initialize scrollable elements
		
	$(".scrollable").scrollable({speed: 750, circular: false, mousewheel: true});
	
	// Overlays
		$(".carousel-btm1 div.item-image, div.port-item").each(function(i){
			var imageAlt = $('img', this).attr('alt');
			$(this).prepend("<div class='overlay'><p>" + imageAlt + "</p></div>");
			});
		
			  $(".carousel-btm1 div.item-image, div.port-item").hover(function(){
				  $('a img', this).css({'border': '4px solid ' + linkColour + ' '})
			  $(this).children('.overlay').stop().fadeTo(200, 0.8);
		  },function(){
			   $('a img', this).css({'border': '4px solid #fff'})
			  $(this).children('.overlay').stop().fadeTo(500, 0);
		  });
		  

		  //fix slider layout css
		  $('#slide1 .grid_2').filter(":first").addClass('alpha');
		  $('#slide2 .grid_2').filter(":first").addClass('alpha');
		  $('#blog2 .grid_2').filter(":first").addClass('alpha');
		 
		  
		  
		  //Webapp Layouts

		 
		  
		  //People webapp	
		  
		   
		  $('.people-wrap .grid_2:nth-child(4n+1)').addClass('alpha');
		  $('.people-wrap .grid_2:nth-child(4n+4)').addClass('omega');
		  
		  	
			  $(".people-wrap .grid_2").hover(function(){
				  $('a img', this).css({'border': '4px solid ' + linkColour + ' '})
			  $(this).children('.overlay').stop().fadeTo(200, 0.8);
		  },function(){
			   $('a img', this).css({'border': '4px solid #fff'})
			  $(this).children('.overlay').stop().fadeTo(500, 0);
		  });
		  
		  
		  
		  // Clickable link	   				           
		  $('.people-wrap .grid_2').click(function(event){
			event.stopPropagation();

			  $(this).children('a').click();
			  
			  return false;
		  });
		    

		//Projects WebApp
		
	$('.port-wrap .port-item').each(function () {
		  var index = $('.port-item').index(this);
			//console.log(index)
		  if (index === 0) {
			$(this).addClass('alpha');
		  } else if (index === 4) {
			$(this).addClass('alpha');
		  } else if (index === 3) {
			$(this).addClass('omega');
		  } else if (index === 7) {
			$(this).addClass('omega');
		  } else if (index === 8) {
			$(this).addClass('alpha');
		  } else if (index === 11) {
			$(this).addClass('omega');
		  } else if (index === 12) {
			$(this).addClass('alpha');
		  } else if (index === 15) {
			$(this).addClass('omega');
		  }
		});
		
		
		// Format webapp results for list view
	var divs = $(".port-wrap .port-item");	
	for(var i = 0; i < divs.length; i+=8) {
	  divs.slice(i, i+8).wrapAll("<div class='row'></div>");
	}
		
	// Large portfolio scroll element	
	$(".scroll-large").scrollable({speed: 750, circular: false, mousewheel: true});
		  
		  
		 $("#slide1 .item-image, #slide2 .item-image").each(function(){
			 
			 if( $(this).hasClass("how") ) {
				 // do nothing
				 
			 } else {
			 
			  $(this).click(function(){
			window.location = $('a', this).attr('href');
			return false;
			 
			 });
			 
			 }
			 
			  });
		 
  
	    $('.port-item').click(function(){
  	window.location = $('a', this).attr('href');
  	return false;
	  });
	  

     $('.proj-links a:first').addClass('pdf').html("Download this case study");
	   
	   
	   // Widget
	   $("#widget-container").css('opacity', 0.4);
	    $("#widget-container").hover(function(){		
			  $(this).stop().fadeTo(200, 1);
		  },function(){	  
			  $(this).stop().fadeTo(500, 0.4);
		  });
		  
		  
		  //Modal Overlay
		  
  $("a[rel]").overlay();
  
  $("div.captchaimg img").css("width","150");
  
  
  
  //Signup redirect/downloads
  
  
  if (pageURL === "/download-confirm.html") { 
  	
	var redirect = rootURL +"/casestudies/MSD_Dual_Language_Leaflet_Web_Version.pdf";
	
	setTimeout( function() {  location=redirect }, 1500 );

		
  } else if (pageURL === "/pdf-download.html") { 
  	
	var download = $.cookie('pdfurl');
	
	$("a.download").attr('href', download );

		
  }
  
  
  $(".top-side ul li").prepend("_");
  
  // Weird layout bug fix for webkit
   
  		
		  
}); //end



	// Input Placeholder
	(function($){$.fn.placeholder=function(options){var defaults={css_class:"placeholder"};var options=$.extend(defaults,options);this.each(function(){if($(this).attr('placeholder')!==undefined){var phvalue=$(this).attr("placeholder");var currvalue=$(this).attr("value");if(phvalue==currvalue){$(this).addClass(options.css_class)}if(currvalue==""){$(this).addClass(options.css_class);$(this).val(phvalue)}$(this).focusin(function(){var ph=$(this).attr("placeholder");if(ph==$(this).val()){$(this).val("").removeClass(options.css_class)}});$(this).focusout(function(){var ph=$(this).attr("placeholder");if($(this).val()==""){$(this).val(ph).addClass(options.css_class)}})}});return this};
	$("input:text").placeholder();  	
	})(jQuery);

