var slideTo = (startPage*6)-5
var startLocation = slideTo +3;


$(function() {
	$('#textCarousel').jcarousel({
      	scroll: 3,
      	start: startLocation,
		wrap: 'circular',
		slideTo: 1,
		//initCallback: mycarousel_initCallback,
		itemLastInCallback:   mycarousel_itemLastInCallback,
        itemVisibleInCallback: {onBeforeAnimation: textCarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: textCarousel_itemVisibleOutCallback}
    });
});





function   mycarousel_itemLastInCallback(carousel, two,three,state) {

	if(state=='init'){carousel.scroll(slideTo)}
};




var textCarousel_itemList = [

    {title: 'text1 <br />goes here', href:'/check_it_out/horse1-inc.html',width:'900',height:'450',thickbox:'yes',complex:''},
	{title: 'text2  <br />goes here', href:'/check_it_out/horse2-inc.html',width:'900',height:'450',thickbox:'yes',complex:''},
    {title: 'text3  <br />goes here', href:'/check_it_out/horse3-inc.html',width:'900',height:'450',thickbox:'yes',complex:''},
    {title: 'text4  <br />goes here', href:'/check_it_out/horse4-inc.html',width:'900',height:'450',thickbox:'yes',complex:''},
  	
  	{title: 'text5  <br />goes here', href:'/check_it_out/horse5-inc.html',width:'900',height:'450',thickbox:"yes",complex:''},
    {title: 'text6 <br />goes here', href:'/check_it_out/horse6-inc.html',width:'900',height:'450',thickbox:'yes',complex:''},
	{title: 'text7  <br />goes here', href:'/check_it_out/horse7-inc.html',width:'900',height:'450',thickbox:'yes',complex:''},
    {title: 'ctext8 <br /> goes here',href:'/check_it_out/horse8-inc.html',width:'900',height:'450',thickbox:'yes',complex:''}
    

];


function textCarousel_itemVisibleInCallback(carousel, item, i, state, evt){
 	var idx = carousel.index(i, textCarousel_itemList.length);
 	var thisItem = textCarousel_itemList[idx - 1];  
 	
 	
    var thisItemHTML = textCarousel_getItemHTML(thisItem,thisItem.thickbox,thisItem.complex) ;    
    var thisWidth = item.width;
    var thisHeight = item.height;
    // Create an object from HTML
     var DOMitem = jQuery(thisItemHTML).get(0);

 	
 	 //Thickboxes
 	if(thisItem.thickbox=="yes"){
 	
 	if(thisItem.complex!="yes"){
 		//Simple thickboxes
   		tb_init(DOMitem);
  	}else{
       	 //Complex thickboxes
       	if(BrowserDetect.browser=="Safari"||BrowserDetect.browser=="Chrome"){
       		//Safari and Chrome do popup
       		$(DOMitem).click(function () {
       			var thisHref= $(this).attr('href');
   				displayWindow(thisHref, 930,490,0);
   				return false;
   			});
       	}else{
         	//Complex thickboxes, FF, IE
			tb_init(DOMitem);
		}  
  	}
  	}
  	
	carousel.add(i, DOMitem);
};




function textCarousel_getItemHTML(item,needsTB,isComplex){
	var theHREF = item.href;

	//default code
	var myHTML='<a href="'+theHREF+'" ><img src="' + item.url + '" width="112" height="93" alt="' + item.title + '" /><p>' +item.title+'</p></a>';
		
      // if needs TB
 	if(needsTB=="yes"){   
       if(isComplex!="yes"){
       		//If it is a thickbox, but not a complex one, do it for everyone
        	//myHTML='<a href="'+theHREF+'?width=' +item.width+'&amp;height='+item.height+'"><img src="' + item.url + '" width="112" height="93" alt="' + item.title + '" /><p>' +item.title+'</p></a>';
      
      //} else if(BrowserDetect.browser!="Safari"&&BrowserDetect.browser!="Chrome"){
        	//If it's a complex thickbox if for  FF, IE only
        	//myHTML='<a href="'+theHREF+'index-inc.shtml?width=' +item.width+'&amp;height='+item.height+'"><img src="' + item.url + '" width="112" height="93" alt="' + item.title + '" /><p>' +item.title+'</p></a>';
        	myHTML='<a href="'+theHREF+'?width=' +item.width+'&amp;height='+item.height+'"><h3>' +item.title+'</h3></a>';
       }     
       
       }
	return myHTML
};


function textCarousel_itemVisibleOutCallback(carousel, item, i, state, evt){carousel.remove(i);};


