

function switchvid() {
	//console.log(isWeddingVid);
	if (!(wasWeddingVid && isWeddingVid)) {
		// only do this if the video is a new one (not if you were watching wedding and it's still wedding)
		if (isWeddingVid) {
			var vid = vidWedding;
		} else {
			var vid = vidOther;
		}
		
		var flashvars = {
			vid: vid
		};
		swfobject.embedSWF(siteURL + "/flash/player.swf", "vid", "640", "390", "9.0.0", siteURL + "/flash/expressInstall.swf", flashvars);
	}
}

var wasWeddingVid;
var isWeddingVid = true;
//console.log(isWeddingVid);


function homepageSlide(el) {
		
		wasWeddingVid = isWeddingVid;
		if ($(el).prevAll().length == 0) {
			isWeddingVid = true;
		} else {
			isWeddingVid = false;
		}
		
		$(el).find("h2 a").removeClass('clickable').parent().siblings('.extended').animate({height: 280},{speed: "slow", queue: "first"});
			
		$("#slidingpanel .intro").fadeOut({speed: 150, queue: "first"})
		$("#slidingpanel .full").fadeIn({speed: 150, queue: "first"});
		
		// hide unclicked item
		$(el).siblings().find('a').addClass('clickable').end().find('.extended').animate({height: 0},{ "duration": "slow", complete: switchvid})			

}

$(document).ready(function(){



	$('#slidingpanel h2 a').click(function() {
	   	if ($(this).hasClass('clickable')) {
			homepageSlide($(this).parents('.promo1'));
		}
		return false;
	});
	
	$('#slidingpanel a.readmore').click(function() {
		homepageSlide($(this).parents('.promo1'));
		return false;
	});




	$('img.alignleft,img.alignright').parents('p').addClass('imageParent');
	
	
	
	// make H2's immediately followed by H3s not underlined
	$('.content h2').each(function() {
		if ($(this).next().is('h3')) {
			$(this).addClass("plain");
		}
	});
	
	
	

	// check JS is enabled and add initialisation classes
	$("body").addClass("js");
	
	
	var el1 = $('.promo2.type1');
	var el2 = $('.promo2.type2');
	equaliseHeights(el1, el2);	
	
	//spreadHeights();
	
	
	
	$('#previous a').click(function() {
		var vidToPlay = $(this).attr('href').substr(5);
		
		$.ajax({
			type: "POST",
			url: template_directory_uri + "/ajax/getVideo.php",
			data: "vidID=" + vidToPlay,
			success: function(msg){
				var obj = eval('(' + msg + ')');
				
				// insert html into page
				$('#promo1-1 .inner').html(obj['txt']);
				
				// play flash movie				
				var flashvars = {
					vid: obj['vid'],
					skin: root_directory_uri + "/flash/SteelExternalAll.swf"
				};
				swfobject.embedSWF(root_directory_uri + "/flash/player.swf", "vid", "633", "356", "9.0.0", root_directory_uri + "/flash/expressInstall.swf", flashvars);
				
			}
		});
		


		
		
	});
	
	
	
	
});


/* compare two elements and increase the smallest element's height so it matches the tallest */
function equaliseHeights(el1, el2) {
	var h1 = el1.height();
	var h2 = el2.height();
	
	if (h1 > h2) {
		el2.height(h1);
	} else {
		el1.height(h2);
	}
}



/* spread heights of divs on homepage to fill empty space */
function spreadHeights() {
	var h1 = $('#hometoppanel').height();
	var h2 = $('.home #promo1-1 .inside').height();
	var h3 = $('.home #promo1-2 .inside').height();

	var diff = h1 - h2 - h3;
	diff = diff - 48;	

	if (diff > 0) {
		$('.home #promo1-1 .inside').height(h2 + Math.floor(diff/2));
		$('.home #promo1-2 .inside').height(h3 + Math.floor(diff/2));
	}	
}




/* font replacement */
Cufon('.style1');
Cufon('.style2, #sidebar h2');
Cufon('.strap p');
Cufon('.strap p span');
Cufon('#hometoppanel h2 a', {
	hover: true
});


