$(document).ready(function(){
	
	/* ---------- Add Relevant Classes to Lists ------ */
	if($.browser.msie && $.browser.version < 9){
	$('ul li:nth-child(odd),ol li:nth-child(odd)').addClass('odd');
	
	/* ---------- Home Blog ------------------------ */
	$('body.index .section3 .blogentries .BlogFeatureList ul li').prepend('<span class="thumb-frame"></span>');
	}		
	
	
/* ------------------ <HR> ----------- */
	$('hr').wrap('<div class="hr"></div>');
	$('div.hr hr').hide();

/* ------------------ Sitemap ----------- */

	$('<div id="pageTitle">Sitemap</div>').insertBefore('#SiteMap');	

/* -------------------- Photogallery --------------- */
	$('#main div.myslides').each(function(){
	
		var slidesHeight = $(this).height();
		var newHeight = slidesHeight - 10;
	
		$(this).css('height', newHeight);
	
	});

/* ------------- Homepage Blog Thumbnails ------------ */
$('.section3 .blogSummary','body.index').each(function(){
    var $this = $(this),
        findThumb = $this.find('img').length;
    
    if(findThumb == 0){
        $this.prepend('<img src="/Templates/images/tormead_blog_thumbnail.jpg" alt="Tormead School Blog" width="118px" height="92px" />');
    }
});

/* ------------- Slider -------------- */
var currentPosition = 0;
var slides = $('.carousel .slide');
var numberOfSlides = slides.length;
 
manageControls(currentPosition);

 $('.thumbs a').bind('click',function(){
			
	var slideWidth = $('#carousel .slide').outerWidth();
		
		$this = $(this);
		currentPosition = $this.attr('rel') - 1;
		// Activate/inactivate controls
        manageControls(currentPosition);
		
		// Move slideInner using margin-left
		$('#carousel #slide-wrap').animate({
		'marginLeft' : slideWidth*(-currentPosition)
		});
		
		return false;
	});
 
function manageControls(position){
	$('.thumbs a').removeClass('active');
	var activeTab = position+1;
	$('.thumbs a[rel='+ activeTab +']').addClass('active');
}

});
