/* SLIDE PLAYER CLASS */
var slides = new Object();

function slide(slideIndex_, showsUris_, showsTitles_, showsThumbs_) {
	this.slideIndex = slideIndex_;

	this.showsUris 		= !showsUris_ 	? null : showsUris_;
	this.showsTitles 	= !showsTitles_ ? null : showsTitles_;
	this.showsThumbs 	= !showsThumbs_ ? null : showsThumbs_;

	this.playerEmbedUrl = null;
	this.embedTypePremium = null;
	this.layoutMode = null;
	this.player = null;
}

function showChange(event) {
	if(event.data.uri) {
		var showUri = event.data.uri;

		//jQuery.each(event.data, function(k, v) {alert(k + '---' + v)});

		jQuery.each(slides, function() {
			if (this.player !== null && event.sourceId == this.player.id) {
				$('#slide-player-shows-' + this.slideIndex + ' .slide-show-container').removeClass('active');

				if(this.showsUris !== null) {
					if((showIndex = jQuery.inArray(showUri, this.showsUris)) >= 0) {
						//$('#slide-show-' + this.slideIndex + '-' + showIndex).addClass('active');
					}
				}

				return;
			}
		});
	}
}
/* SLIDE PLAYER CLASS */

/* customersmenu carousel start */
function activateShow(slideIndex, showIndex, showUri) {
	$('#slide-player-shows-' + slideIndex + ' .slide-show-container').removeClass('active');
	$('#slide-show-' + slideIndex + '-' + showIndex).addClass('active');

	slides[slideIndex].player.setURI(showUri);
}

function customersmenucarousel_initCallback(carousel, state) {
	if(state == "init") {
		$('#customersmenu-first').bind('click', function() {
			carousel.scroll(1, true);
			return false;
		});

		$('#customersmenu-last').bind('click', function() {
			carousel.scroll(carousel.options.size);
			return false;
		});
	}
}

function customersmenucarousel_buttonNextCallback(carousel, controlElement, status) {
	if(status == true) {
		$('#customersmenu-next').unbind('click');
		$('#customersmenu-next').bind('click', function() {
			carousel.next();
			return false;
		});
	}
	else if(status == false) {
		$('#customersmenu-next').unbind('click');
		$('#customersmenu-next').bind('click', function() {
			return false;
		});
	}
}

function customersmenucarousel_buttonPrevCallback(carousel, controlElement, status) {
	if(status == true) {
		$('#customersmenu-prev').unbind('click');
		$('#customersmenu-prev').bind('click', function() {
			carousel.prev();
			return false;
		});
	}
	else if(status == false) {
		$('#customersmenu-prev').unbind('click');
		$('#customersmenu-prev').bind('click', function() {
			return false;
		});
	}
}

function customersmenucarousel_itemVisibleInCallback(carousel, object, index, state) {
	$('#customersmenu-current-slide').html(index);
	$('#customersmenu-total-slides').html(carousel.options.size);
}

function customersmenucarousel_itemVisibleOutCallback(carousel, object, index, state) {
}
/* customersmenu carousel end */

/* customerscategories carousel start */
function customerscategoriescarousel_initCallback(carousel, state) {
	if(state == "init") {
		$('.customerscategories-first').bind('click', function() {
			carousel.scroll(1, true);
			return false;
		});

		$('.customerscategories-last').bind('click', function() {
			carousel.scroll(carousel.options.size);
			return false;
		});
	}
}

function customerscategoriescarousel_buttonNextCallback(carousel, controlElement, status) {
	if(status == true) {
		$('.customerscategories-next').unbind('click');
		$('.customerscategories-next').removeClass('disabled').bind('click', function() {
			carousel.next();
			return false;
		});
	}
	else if(status == false) {
		$('.customerscategories-next').unbind('click');
		$('.customerscategories-next').addClass('disabled').bind('click', function() {
			return false;
		});
	}
}

function customerscategoriescarousel_buttonPrevCallback(carousel, controlElement, status) {
	if(status == true) {
		$('.customerscategories-prev').unbind('click');
		$('.customerscategories-prev').removeClass('disabled').bind('click', function() {
			carousel.prev();
			return false;
		});
	}
	else if(status == false) {
		$('.customerscategories-prev').unbind('click');
		$('.customerscategories-prev').addClass('disabled').bind('click', function() {
			return false;
		});
	}
}

function customerscategoriescarousel_itemVisibleInCallback(carousel, object, index, state) {
	$('.customerscategories-current-slide').html(index);
	$('.customerscategories-total-slides').html(carousel.options.size);

	$('.customerscategories-first').unbind('click');
	$('.customerscategories-last').unbind('click');

	if(index > 1) {
		$('.customerscategories-first').removeClass('disabled').bind('click', function() {
			carousel.scroll(1, true);
			return false;
		});
	}
	else {
		$('.customerscategories-first').addClass('disabled').bind('click', function() {
			return false;
		});
	}

	if(index < carousel.options.size) {
		$('.customerscategories-last').removeClass('disabled').bind('click', function() {
			carousel.scroll(carousel.options.size);
			return false;
		});
	}
	else {
		$('.customerscategories-last').addClass('disabled').bind('click', function() {
			return false;
		});
	}
}

function customerscategoriescarousel_itemVisibleOutCallback(carousel, object, index, state) {
}
/* customerscategories carousel end */

/* customersmpage carousel start */
function customerspagecarousel_initCallback(carousel, state) {
	if(state == "init") {
	}
}

function customerspagecarousel_buttonNextCallback(carousel, controlElement, status) {
	if(status == true) {
		$('#customerspage-next').unbind('click');
		$('#customerspage-next').removeClass('disabled').bind('click', function() {
			carousel.next();
			return false;
		});
	}
	else if(status == false) {
		$('#customerspage-next').unbind('click');
		$('#customerspage-next').addClass('disabled').bind('click', function() {
			return false;
		});
	}
}

function customerspagecarousel_buttonPrevCallback(carousel, controlElement, status) {
	if(status == true) {
		$('#customerspage-prev').unbind('click');
		$('#customerspage-prev').removeClass('disabled').bind('click', function() {
			carousel.prev();
			return false;
		});
	}
	else if(status == false) {
		$('#customerspage-prev').unbind('click');
		$('#customerspage-prev').addClass('disabled').bind('click', function() {
			return false;
		});
	}
}

function customerspagecarousel_itemVisibleInCallback(carousel, object, index, state) {
	$('#customerspage-current-slide').html(index);
	$('#customerspage-total-slides').html(carousel.options.size);
}

function customerspagecarousel_itemVisibleOutCallback(carousel, object, index, state) {
}
/* customerspage carousel end */

$(document).ready(function(){
	$("#customers-autocomplete").autocomplete("/customers/search/", {
		scrollHeight: 200,
		width: 300,
		formatItem: function (item) {
			if(item[0] == "No results found in our database.") {
				return item[0];
			}
			else {
				return item[2];
			}
		},
		formatResult: function (item) {
			if(item[0] == "No results found in our database.") {
				return item[0];
			}
			else {
				return item[2];
			}
		}
	}).result(function(event, item) {
		if(item[0] == "No results found in our database.") {
			$('#customers-autocomplete').attr("value", "");
		}
		else {
			window.location = '/customers/customer/' + item[0] + '/' + item[1];
		}
	});

	if (typeof customersmenuselectedpage != "undefined" && customersmenuselectedpage > 0)
		startpage = customersmenuselectedpage;
	else
		startpage = 1;

	$('#customersmenu').jcarousel({
		key: 'customersmenu',
		buttonNextHTML: "<div></div>",
		buttonPrevHTML: "<div></div>",
		scroll: 1,
		start: startpage,
		easing: "easeInExpo",
		initCallback: customersmenucarousel_initCallback,
		buttonNextCallback: customersmenucarousel_buttonNextCallback,
		buttonPrevCallback: customersmenucarousel_buttonPrevCallback,
		itemVisibleInCallback: customersmenucarousel_itemVisibleInCallback,
		itemVisibleOutCallback: customersmenucarousel_itemVisibleOutCallback
	});

	$('#customerspage').jcarousel({
		key: 'customerspage',
		buttonNextHTML: "<div></div>",
		buttonPrevHTML: "<div></div>",
		scroll: 1,
		start: 1,
		easing: "easeInExpo",
		wrap: "last",
		initCallback: customerspagecarousel_initCallback,
		buttonNextCallback: customerspagecarousel_buttonNextCallback,
		buttonPrevCallback: customerspagecarousel_buttonPrevCallback,
		itemVisibleInCallback: customerspagecarousel_itemVisibleInCallback,
		itemVisibleOutCallback: customerspagecarousel_itemVisibleOutCallback
	});

	$('#customerscategories').jcarousel({
		key: 'customerscategories',
		buttonNextHTML: "<div></div>",
		buttonPrevHTML: "<div></div>",
		scroll: 1,
		start: 1,
		easing: "easeInExpo",
		initCallback: customerscategoriescarousel_initCallback,
		buttonNextCallback: customerscategoriescarousel_buttonNextCallback,
		buttonPrevCallback: customerscategoriescarousel_buttonPrevCallback,
		itemVisibleInCallback: customerscategoriescarousel_itemVisibleInCallback,
		itemVisibleOutCallback:customerscategoriescarousel_itemVisibleOutCallback
	});
});