function set_theme(title, themeid) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) { 
				a.disabled = false;
			}
		}
	}
	$.ajax({
	url: '/ajax/function.php',
	data: 'method=set-theme&themeid=' + themeid,
	error: function() {
		alert('Unable to save theme setting');
		}
	});		
}

$(function(){
	$(".in").hide();		
	$(".box-small-status").click(function(){
		$("~ div:first", this).slideToggle();
		if ($("> .in", this).is(":hidden")){	
			$("> .in", this).show();	
			$("> .out", this).hide();
		} else {	
			$("> .in", this).hide();	
			$("> .out", this).show();						
		}	
	});
	$(".sortable").sortable({
		handle:"h3",
		connectWith:[$(".col-one"),$(".col-two"),$(".col-three")],
		placeholder:"dropspot",
		cancel: $('fixed'),
		update: function() {
			var order = '';
			$(".sortable").each(function() {
				order += '&' + $(this).sortable("serialize");
			});
			$.ajax({
			url: '/ajax/function.php',
			data: 'method=contentwidget-reorder&contentid=' + $('#contentid').val() + order,
			error: function() {
				alert('Unable to save order');
				}
			});		
		}
	});
	
	$("#feature-content").serialScroll({
		items:"#feature-content-wrapper>div",
		duration:1500,
		force:true,
		cycle:true,
		constant:false,
		axis:'x',
		interval:10000,
		navigation:"#feature-nav li a",
		onBefore:function( e, elem, $pane, $items, pos ){
			$("#feature-nav li a").removeClass("active");
			$(this).addClass("active");
		}
	});
		
	$("#feature-content").hover(function(){
		$(this).trigger("stop");
	},function(){
		$(this).trigger("start");
	});
	
	
	$("#clinicmast-content").serialScroll({
		items:"#clinicmast-content-wrapper>div",
		duration:1500,
		force:true,
		cycle:true,
		constant:false,
		axis:'x',
		interval:10000
	});	
	
	
	$("#content ul.gallery li a").lightbox();
	

	getTwitters('tweet', { 
	  id: 'PetDoctorsVet', 
	  count: 1, 
	  enableLinks: true, 
	  ignoreReplies: true, 
	  clearContents: true,
	  template: '"%text%" <a href="http://twitter.com/%user_screen_name%/statuses/%id%/">%time%</a>'
	});
	
	var numpets = 1;
	
	// Connect Card
	$('.addpetlink').click(function () {
		var peti = 0;
		var ignore = false;
		$('#connectcard-pets').children().each(function() {
			peti = peti + 1;
			if ($(this).css('display') == 'none' && !ignore) {
				numpets = peti;
				ignore = true;
				$(this).slideDown();
				$('.removepetlink', this).css('display', 'block');
			}
		});
		if (!ignore) {
			alert('You can only add a maximum of six pets.');
		}
		return false;
	});
	
	// $('.removepetlink').css('display', 'none');
	
	$('.removepetlink').click(function () {
		$(this).parent().parent().fadeOut();
		$('input.petname', $(this).parent().parent()).val('');
		return false;
	});
	
	$('input.petname').each(function() {
		if ($(this).val()) {
			$(this).parent().parent().removeClass('hidden');
		}
	});
	
});