//Stimson  JavaScript Library
var ixMainPicture = 0;


function flagDog(id) {
	$.post('ajax.php',{
		cmd: 'flagDog',
		id: id,
		ident: compareIdent
	}, function (response) {
		if (response.status == 'ok') {
			$("#comparer").html(response.html);
		}; //if
	}, 'json');
}
function unFlagDog(id) {
	var el = $(this).parent();
	$.post('ajax.php',{
		cmd: 'unFlagDog',
		id: id,
		ident: compareIdent
	}, function (response) {
		$("#cDog" + id).remove();
	}, 'json');
}

function ChangeMainPicture() {
	var p = $(".MainPicture");
	if (p.length > 0) {
		$(p[ixMainPicture]).fadeOut(1700);
		ixMainPicture++;
		if (ixMainPicture >= p.length) {
			ixMainPicture = 0;
		}; //if
		$(p[ixMainPicture]).fadeIn(1700);
		var caption = $(p[ixMainPicture]).attr('title');
		if (caption == '') caption = 'We have been loving our bullies for over 25 years!';
		var el = $('<div class="MainPictureCaption" style="display:none;">' + caption + '</div>');
		$("#MainPictureCaptionContainer .MainPictureCaption").fadeOut(1700);
		$("#MainPictureCaptionContainer").append(el);
		el.fadeIn(1700);
		setTimeout("ChangeMainPicture();", 3000);
	}; //if
}

function titlePictureFader(component) {
	var p = $(".titlePictureImg", $(component));
	ix = $(component).data('ix');
	if (p.length > 0) {
		$(p[ix]).fadeOut(1700);
		ix++;
		if (ix >= p.length) {
			ix = 0;
		}; //if
		$(p[ix]).fadeIn(1700);
		$(component).data('ix',ix);
		setTimeout(function () {
			titlePictureFader(component);
		}, 3000);
	}; //if
}

String.prototype.rot13 = function(){
    return this.replace(/[a-zA-Z]/g, function(c){
        return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
    });
};

$(function () {
	setTimeout("ChangeMainPicture()",2000);
	$("#blogBox").click(function () {
		var id = $(this).attr('data-id');
		if (id != undefined) {
			location.href="bulldog-blog.php?id=" + id;
		}; //if
	});
	
	$("#cControl").live('click',function () {
		var state = $(this).attr('data-state');
		if (state == 'down') {
			$("#cControl").css('background-image','url(images/rolldownW.png)').attr('data-state','up');
			$("#cList").slideUp();
		} else {
			$("#cControl").css('background-image','url(images/rollupW.png)').attr('data-state','down');
			$("#cList").slideDown();
		}; //if
	})
	
	
	$(".flagDog").live('click',function () {
		var id = $(this).attr('data-id');
		flagDog(id);
	});
	
	$(".cDogRemove").live('click',function () {
		var id = $(this).attr('data-id');
		unFlagDog(id);
		return false;
	});
	
	$(".cDog").live('click',function () {
		var id = $(this).attr('data-id');
		location.href = "dog.php?id=" + id;
	});
	
	
	$(".titlePictureDiv").each(function () {
		var mode = $(this).attr('data-mode');
		switch (mode) {
			case 'gallery':
				break;
			case 'fader':
				$(this).data('ix',0); // store the picture index
				titlePictureFader(this);
				break;
		}; //switch
	});
	$("#hanging-ident").click(function () {
		location.href = 'index.php';
	}); 
	$(".galleryBox a").fancybox({
		'type': 'swf',
		'swf'       : {'wmode':'transparent','allowfullscreen':'true', height:560}
	});
	
	// decrypt email
	$(".email13").each(function () {
		var email = $(this).html().rot13();
		$(this).html(email);
	});
	
	$("a[href^=mail13]").each(function () {
		var email = $(this).attr('href');
		if (email.length > 7) {
			email = email.substr(7).rot13().replace('#','@');
			$(this).attr('href',email);
		}; //if
	});
	
});


