/*
Bookmark Script
*/
$("a.bookmark").click(
	function(){
		var bookmarkurl = $(this).attr('href');
		var bookmarktitle = $(this).attr('title');
		if (document.all)
		window.external.AddFavorite(bookmarkurl,bookmarktitle);
		else if (window.sidebar)		alert('This feature only works for Internet Explorer, use Control+D to bookmark This website');
		else if( window.opera && window.print )		alert('This feature only works for Internet Explorer, use Control+T to bookmark This website');
		
		return false; // Do not follow link
		}	);/*Colorbox CallThis is for all inline contentthe link needs to be done like this...<a href="#blah" class="colorbox">blah</a>and the hidden div like this...<div class="details"><div id="blah" class="colorbox"></div></div>*/$("a.colorbox").click(	function(){			var href = "";			href = $(this).attr("href");			$(".colorbox").colorbox({width:"600px", inline:true, href:href});			}	);
$(".colorboxphoto").colorbox();

/* Slideshow */

/* this should be in head */
$(document).ready(function() {		
	
	//Execute the slideShow, set 4 seconds for each images
	slideShow(5000);

});

/* Slideshow function */
/*
*
*	Add class "slideshow" to a ul
*	Add class "show" to first li *Optional
*	add image titles to img TITLE attribute
*	add descriptions to img ALT attribute
*
*/

function slideShow(speed) {


	//append a LI to the UL list for displaying caption
	$('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3><div class="text"></div></div></li>');

	//Set the opacity of all images to 0
	$('ul.slideshow li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.slideshow li:first').css({opacity: 1});
	
	//Get the caption of the first image from appropriate attribute and display it
	$('#slideshow-caption h3').html($('ul.slideshow li:first').find('img').attr('title'));
	$('#slideshow-caption .text').html($('ul.slideshow li:first').find('img').attr('alt'));
		
	//Display the caption
	$('#slideshow-caption').css({opacity: 1, top:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('gallery()',speed);
	
	//pause the slideshow on mouse over
	$('ul.slideshow').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery()',speed);			
		}
	);
	
}

function gallery() {

	//if no IMGs have the show class, grab the first image
	var current = ($('ul.slideshow li.show') ?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
		
	//Get next image caption
	var title = next.find('img').attr('title');	
	var desc = next.find('img').attr('alt'); 

	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	//Update the caption to perform funky animated transition
	$('#slideshow-caption').animate({ 
		opacity:0,
		right:'-=244px'
		}, 400, function(){
			$('#slideshow-caption h3').html(title); 
			$('#slideshow-caption .text').html(desc);
			$('#slideshow-caption').css({'right':'-244px'});
			$('#slideshow-caption').animate({
				opacity: 1,
				right: ['+=244px','swing']}, 400
			);
	});

	//Hide the current image
	current.animate({opacity: 0}, 1000).removeClass('show');

}

/*
Portfolio
Just save all the big images and put them in a list.
Thumbnails auto generated.
markup like...

<div id="portfolio" class="svwp">
    <ul>
		<li><img src="every-big-image.jpg" alt="description to show in .typo" /></li>
    </ul>
</div>

*/

$(window).bind("load", function() { 
    $("div#portfolio").slideViewerPro({ 
			autoslide: true,
			typo: true,
			typoFullOpacity: 0.8,
			shuffle: false,
			galBorderWidth: 0,
			galBorderColor: "#fff",
			thumbs: 3,
			thumbsPercentReduction: 21,
			thumbsTopMargin: 0,
			thumbsRightMargin: 10,
			thumbsBorderWidth: 5,
			thumbsBorderColor: "#317C21",
			thumbsActiveBorderColor: "#317C21",
			thumbsBorderOpacity: 0.6, // could be 0, 0.1 up to 1.0
			thumbsActiveBorderOpacity: 1.0, // could be 0, 0.1 up to 1.0
			easeTime: 750,
			asTimer: 3500,
			thumbsVis: true,
			easeFunc: "easeInOutExpo",
			buttonsWidth: 15,
			buttonsTextColor: "#fff",
			leftButtonInner: "<img src='images/arrow-left.png' alt='previous' title='' />", //could be an image "<img src='images/larw.gif' />" or an escaped char as "&larr";
			rightButtonInner: "<img src='images/arrow-right.png' alt='next' title='' />" //could be an image or an escaped char as "&rarr";
    }); 
}); 
