$(document).ready( function() {
	/* slideshow */
	if ($('div.contents_gallery_item').length) var images = new Array();
	$('div.contents_gallery_item').each( function() {
		var image = {
			thumbs : $(this).find('img').attr('thumbs').split(';'),
			main : $(this).find('img').attr('src')
		};
		images.push(image);
	});
	
	$('div.contents_gallery_item > h3 > a').live('mouseover mouseout', function(event) {
		if (event.type=='mouseover') {
			$(this).children('img').addClass('slideshow');
			slideShow($(this).children('img').get());
		}
		else {
			$(this).children('img').removeClass('slideshow') .attr('src',images[$('div.contents_gallery_item').index($(this).parent('h3').parent('div'))].main);
		};
	});

	function slideShow(image, count) {
		if ($(image).hasClass('slideshow')) {
			var tmp = {
				thumb : new Image(),
				time : 500,
				count : 0,
				intl : setInterval( function() { tmp.count++;}, 10)
			};
			var index = $('div.contents_gallery_item').index($(image).parents('div.contents_gallery_item'));
			count = count ? count : 0;
			tmp.thumb.onload = function() {
				$(image).attr('src',tmp.thumb.src);
				clearInterval(tmp.intl);
				count = count<images[index].thumbs.length-1 ? count + 1 : 0;
				tmp.time = (tmp.time - tmp.count*10 > 0) ? tmp.time - tmp.count : 0;
				setTimeout( function() { slideShow(image, count);}, tmp.time);
			};
			tmp.thumb.src = images[index].thumbs[count];
		};
	};
	/* slideshow */
	
	/* bookmark */
	$('div.bookmark a').click( function() {
		if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel("Pornerbros.com","http://www.pornerbros.com", "");
		else {
			if (typeof window.external == "object" && navigator.userAgent.toLowerCase().indexOf('webkit')==-1) window.external.AddFavorite("http://www.pornerbros.com", "Pornerbros.com");
			else {
				alert("To bookmark this page, please press Ctrl+D (or Command+D under MacOS) after closing this dialogue");
			};
		};
		return false;
	});
	/* bookmark */
});
