// JavaScript Document Created nov 2009 Frontend Design ~ James Ing



 $(document).ready(function(){ 
							
	$variables = [];						

	// Hides any new zealand or australian content appearing on each others site.
	$(".AU .nz-content").remove();
	$(".NZ .oz-content").remove();


/*  
	if($(".NZ").length) {  // Inverted for testing
		$(".oz-swap").each( function() { 
			$ozcontent = $(this).html();
			$(".nz-swap").before("<div class='oz-swap'>"+$ozcontent+"</div>");
			$(this).remove();
		})
	}*/


	if($(".AU").length) { //if we're viewing an ozzie page, switch ozzie content first
		$(".oz-swap").each( function() { 
			$ozcontent = $(this).html();
			$(".nz-swap").before("<div class='oz-swap'>"+$ozcontent+"</div>");
			$(this).remove();
		})
	}

	if($(".NZ").length) { // if we're viewing nz page, switch nz content first.
		$(".nz-swap").each( function() { 
			$nzcontent = $(this).html();
			$(".oz-swap").before("<div class='nz-swap'>"+$nzcontent+"</div>");
			$(this).remove();
		})
	}

	if($("#pagination").is(':empty')) { // if there's no pagination remove the element
		$("#pagination").parent().parent().remove();
	} 

	$('#footer-links .pagination').remove(); // remove pagination that appears in footer
	
	$("#news .blogsitesummary li:odd").find("a").addClass("even"); 
	
	if($("#banr1").length) { // used for the home page. Setup the scroller
		$variables.homefeatureIndex = 2;
		$homepageScroller();
		$("#leftItem").hover( function() {
			$homeBannerOver(1);						   
		}, function() {
			$variables.homefeatureIndex = 2;
			$homepageScroller();
		});
		$("#rightItem").hover( function() {
			$homeBannerOver(3);						   
		}, function() {
			$variables.homefeatureIndex = 1;
			$homepageScroller();
		});
		$("#centreItem").hover( function() {
			$homeBannerOver(2);						   
		}, function() {
			$variables.homefeatureIndex = 3;
			$homepageScroller();
		});
	}
	
	function $homeBannerOver(index) {
		clearInterval($variables.homeTimer);
			$("#banner .bannerImg").fadeOut("slow", function() {
				$("#banr"+index).css("top", 0);
			});
			$("#banr"+index).fadeIn("slow");
	}
	
	
	function $homepageScroller() {
		clearInterval($variables.homeTimer);
		$variables.homeTimer = setInterval(function() {
			if($variables.homefeatureIndex > 3) {
					$variables.homefeatureIndex = 1;
				}
				$("#banner .bannerImg").fadeOut("slow", function() {
					$("#banr"+$variables.homefeatureIndex).css("top", 0);
				});
				$("#banr"+$variables.homefeatureIndex).fadeIn("slow", 
					function(){
						$variables.homefeatureIndex++;														 					});
		},8000);	
	}

if($(".cross-sell-case-study").length) { 

		$(".cross-sell-case-study").each(function() {
		/* 
		For the 3rd column cross case studies, wrap the a link in a div to float it next
		to the image.
		Take the img read it's variables, remove it, then reinsert it using business 
		catalyst's inbuilt thumbnail builder.
		*/
		$(this).find("a").wrap("<div class='scc-bottom'></div>").after("<div class='clear'></div>");
		var imgPath = $(this).find("img").attr('src');
		var linkPath = $(this).find("a").attr('href');
		$(this).find("img").remove();
		$(this).find("a").parent().parent().prepend("<img src='/Utilities/ShowThumbnail.aspx?USM=1&W=170&H=100&R=1&Img="+imgPath+"' />");
		$(this).find("img").css('display', 'block').wrap("<div class='case-study-thumb-mask'></div>");

});
}

	

	if($(".capabilities-overview").length) {
		$(".capabilities-overview").find('div.capaBox').each(function() {
			var caplink = $(this).find('h5').find('a').attr('href');
			$(this).find('img').wrap('<a href="'+caplink+'"></a>');
			
		});
	}
	
	if($("#youtubelink").length) {
	if($("#youtubelink").attr('href') != '') {   
$variables.playerCode =  $("#youtubelink").attr('href').substr(($("#youtubelink").attr('href').indexOf('v')+2))	
	$("#youtubelink").after("<object width='245' height='201'><param name='movie' value='http://www.youtube.com/v/"+ $variables.playerCode +"&hl=en_US&fs=1&rel=0&color1=0x00a0af&color2=0x00a0af&border=0'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/" + $variables.playerCode  + "&hl=en_US&fs=1&rel=0&color1=0x00a0af&color2=0x00a0af&border=0' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='245' height='201'></embed></object>");
	$("#youtubelink").remove();
	$(".utube-vid object").show();	
	} else {
		$(".utube-vid").css('display', 'none');
	}
}

	if($(".col480 .youtube-vid").length) {
		$(".col480").find("a.youtube-vid").each(function() {

			if($(this).attr('href') != '') {
		$(this).parent().find('img').fadeOut("fast");
				$variables.playerCoder =  $(this).attr('href').substr(($(this).attr('href').indexOf('v')+2));
	$(this).after("<object width='480' height='245'><param name='movie' value='http://www.youtube.com/v/"+ $variables.playerCoder +"&hl=en_US&fs=1&rel=0&color1=0x00a0af&color2=0x00a0af&border=0'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/" + $variables.playerCoder  + "&hl=en_US&fs=1&rel=0&color1=0x00a0af&color2=0x00a0af&border=0' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='480' height='245'></embed></object>");
		$(this).remove();
		
			} else {
				$(this).remove();
			}
		 });
				
	}

	if($("#side-ads").find("h5").text() == '') {
		$("#side-ads").remove();
	}

	$("ul.case-study-list li img").remove();
	
	$("div.cross-media .moreCaseBox").each(function() { 
 		$(this).prepend('<h6></h6>');
		$(this).find('h6').html($("#contentPage .moreCaseBox h1").html());
		$(this).find('h1').remove();
		$(this).find('div').removeClass('borderBottom');
	});

	if($(".bottom-cross-case").length) {
		$(".bottom-cross-case").each( function() {
			$(this).find("img").remove();
		})
	}
    if($(".core-offer").length) {
		$(".offeringBox:last").removeClass("borderBottom");
	}



	if($("#side-brochure").find("a").length) {

		$("#side-brochure").css('display', 'block');
	}
	
	$('.flickr_badge_image').each( function() {
		$variables['imageHeight'] = $(this).height();
		$variables['imageWidth'] = $(this).width();
		$(this).prepend("<div class='imageRollOver'></div>");
		$('.imageRollOver').css({height: $variables['imageHeight'], width: $variables['imageWidth'], display: 'block', opacity:'0.0'});
		
	});

	$('.case-study-thumb-mask').each( function() {
		$variables['imageHeight'] = $(this).height();
		$variables['imageWidth'] = $(this).width();
		$(this).prepend("<div class='scc-imageRollOver'></div>");
		$('.scc-imageRollOver').css({height: $variables['imageHeight'], width: $variables['imageWidth'], display: 'block', opacity:'0.0'});
		
	});

$('.capabilities').find('.capaBox').find('img').each( function() {
		$variables['imageHeight'] = $(this).height();
		$variables['imageWidth'] = $(this).width();
		$(this).before("<div class='cap-imageRollOver'></div>");
		$('.cap-imageRollOver').css({height: $variables['imageHeight'], width: $variables['imageWidth'], display: 'block', opacity:'0.0'});
		
	});



$('.imageRollOver').click(function() { 
			window.open ( $(this).parent().find('a').attr('href'));
		});

$('.scc-imageRollOver').click(function() { 
	window.location = $(".scc-bottom").find('a').attr('href');
});

$('.imageRollOver,  .scc-imageRollOver, .cap-imageRollOver').hover(function() {
			$(this).fadeTo(100, .3);
			$(this).css({cursor: 'pointer'});
		}, function() { 
			$(this).fadeTo(100, .0);
		});
	
	$("#companyIntro").click(function() {
		window.location = ($("#companyIntro").find('a').attr('href'));

	});

if($("#text-roller ol").length) {
		$("#text-roller").css('visibility', 'visible');
	$("#text-roller ol").liScroll(); 

    }

	/* ******************************** KORDIA INSIGHTS ***************************** */

if($('.rating-display p').find('strong').html() != '0' && $('.rating-display p') .length) {
	$variables.starOne = $(".insights .stars").find('img').attr('src');
	$variables.starOne = $variables.starOne.substr(16,1);
	$variables.starReplaceStr = "/images/insights/star"+ $variables.starOne+".png";
	$(".insights .stars").find('img').attr('src', $variables.starReplaceStr);
	$(".insights .stars").find('img').css({ width: '91px', height: '14px'});
	
	
	$(".comment-container").each(function() {
		$variables.starTwo = $(this).find('img').attr('src');
		$variables.starTwo = $variables.starTwo.substr(16,1);
		$variables.starReplaceStr = "/images/insights/star"+ $variables.starTwo+".png";
		$(this).find('img').attr('src', $variables.starReplaceStr);
		$(this).find('img').css({ width: '91px', height: '14px'});
	});
}



		$('.more-insight-list').each(function() {
			for(i=0;i<2;i++) {
				$('.more-insight-list').before($(this).find('div:eq(0)'));
			}
		})

		$('.white-papers-list').each(function() {	
			for(i=0;i<3;i++) {
				$('.white-papers-list').before($(this).find('p:eq(0)'));
			}
		})

		$('.services-list').each(function() {
			for(i=0;i<2;i++) {
				$('.services-list').before($(this).find('div:eq(0)'));
			}
		})





		$('.white-papers .expand-column').click(function() {
			$('.white-papers-list').slideDown();
				console.log('slide down button clicked');
			//$(this).fadeOut();
			$(this).addClass('expanded-column').removeClass('expand-column').html('Show less whitepapers');
			return false;
		});
		
		$('.white-papers .expanded-column').click(function() {
			$('.white-papers-list').hide();
				console.log('slide up button clicked');
			//$(this).fadeOut();
			$(this).addClass('expand-column').removeClass('expanded-column').html('Show more whitepapers');
			return false;
		});
		
		
		
		

		$('.utube-vid .expand-column').click(function() {
			$('.more-insight-list').slideDown();
			$(this).fadeOut();
			return false;
		});


		$('.services .expand-column').click(function() {
			$('.services-list').slideDown();
			$(this).fadeOut();
			return false;
		});



		if($('.download-section').find('a').attr('href') == '') {
			$('.download-section').addClass('hide');
		}


		$('.expand-column').removeClass('hide');

		$variables.descriptionHeight = $('.insight-description').height();
		$('.insight-description').css({ height: 50 });
	
		$('.insight-description').find('a.expander').click(function() {
			$('.insight-description').animate({
			'height': $variables.descriptionHeight
			})
			$(this).addClass('open-expander');
			$(this).removeClass('expander');
			//console.log('it has expanded');
			return false;
		});

		$('.insight-description').find('a.open-expander').click(function() {
			$('.insight-description').animate({
			'height': 50
			})
			$(this).addClass('expander');
			$(this).removeClass('open-expander');
			//console.log('it has shrunk');
			return false;
		});
      $variables.seemorecomments = $('a.see-more').find('a').attr('href');
      $variables.seemorecomments +="#see-comments";
       $('a.see-more').find('a').attr('href', $variables.seemorecomments);
	

$("input#RFullName").val('');
$("input#REmailAddress").val('');
$("input#RWebsite").val('');
$("textarea#RFeedback").val('');
$("input#CaptchaV2").val('');






});
 $(window).load(function(){ 
if($("#twitter-feed").length) {
		if($(".SteveRKordia").length) {
			$(".SteveRKordia").tweet({
           		 username: "SteveRKordia",
           	 	avatar_size: 0,
           	 	count: 2,
           	 	loading_text: "Retrieving Feed..."
        	});
		} 
		if($(".reganhughes").length) {
			$(".reganhughes").tweet({
           		 username: "reganhughes",
           	 	avatar_size: 0,
           	 	count: 2,
           	 	loading_text: "Retrieving Feed..."
        	});
		} 
		if ($(".murraygoodman").length) {
       		$(".murraygoodman").tweet({
            	username: "murraygoodman",
            	avatar_size: 0,
            	count: 2,
            	loading_text: "Retrieving Feed..."
        	});
		} 
		if ($(".myerskevin").length) {
       		$(".myerskevin").tweet({
            	username: "myerskevin",
            	avatar_size: 0,
            	count: 2,
            	loading_text: "Retrieving Feed..."
        	});
		}

	}
});
$