// This script was written by George Paschetto specifically 
// for pedaledesign.com/portfolio. Email: gtpaschetto@mckendree.edu

// new approach (GTP Feb 09)
// use cookies to pass starting position of carousel
var start1 = "c1.start";
var start2 = "c2.start";
var start3 = "c3.start";
var start4 = "c4.start";
var postern = 1;
var identityn = 1;
var printmerchn = 1;
var artprintn = 1;

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	// our only cookie uses a single integer. If no cookie exists, we default to 1
	return '1';
}

// callback functions for jquery.jcarousels
// called when carousel scrolls to new position
function callback1(oreq, oitem, ino, actstring)
{
	document.cookie = start1 + '=' + ino;
}
function callback2(oreq, oitem, ino, actstring)
{
	document.cookie = start2 + '=' + ino;
}
function callback3(oreq, oitem, ino, actstring)
{
	document.cookie = start3 + '=' + ino;
}
function callback4(oreq, oitem, ino, actstring)
{
	document.cookie = start4 + '=' + ino;
}

// get cookies to initialize carousels
identityn = parseInt(readCookie(start1));
if ((identityn == 0)||(isNaN(identityn))) { identityn = 1; }
postern = parseInt(readCookie(start2));
if ((postern == 0)||(isNaN(postern))) { postern = 1; }
printmerchn = parseInt(readCookie(start3));
if ((printmerchn == 0)||(isNaN(printmerchn))) { printmerchn = 1; }
artprintn = parseInt(readCookie(start4));
if ((artprintn == 0)||(isNaN(artprintn))) { artprintn = 1; }

// initialize the four carousels
jQuery(document).ready(function() {
	jQuery('#identity-carousel').jcarousel({
		start: identityn,
		itemFirstInCallback: { onBeforeAnimation: callback1 }
	});
	jQuery('#poster-carousel').jcarousel({
		start: postern,
		itemFirstInCallback: { onBeforeAnimation: callback2 }

	});
	jQuery('#print-carousel').jcarousel({
		start: printmerchn,
		itemFirstInCallback: { onBeforeAnimation: callback3 }

	});
	jQuery('#art-carousel').jcarousel({
		start: artprintn,
		itemFirstInCallback: { onBeforeAnimation: callback4 }

	});
});