/*$(document).ready(function() {*/
  listOfBrends.initialize();
  
  
	/*$('a.lightbox').lightBox({fixedNavigation:true});*/

	$(document).bind("ajaxComplete", function(){
    	$('a.lightbox').lightBox({fixedNavigation:true});
	});


/*});*/

var listOfBrends = {
	left: 0, //left cords
	right: 0, //right cords
	width: 0, //container width
	elementCount: 0, //elemetns count in container
	showElementCount: 6, //count of elements which are showes in container
	//parameters
	elementWidth: 107, //element width
	leftArrowId: "left-arrow", //left arrow id name
	rightArrowId: "right-arrow", //right arrow id name
	containerId: "collection-list-ul", //container id name
	elementClassName: "", //element class name
	useTagName: false, //use tag name or class name
	tagName: "li", //element tag name
	hideInArrows: true, //hide an arrow when elements are end
	//function return elements count in container and initialize width of container
	initialize: function() {
		var count = 0;
		var obj = null;
		if (listOfBrends.containerId.length > 0) {
			if(obj = document.getElementById(listOfBrends.containerId)) {
				if (obj.nodeType == 1) {
					var n = obj.childNodes;
					for (var i=0; i<n.length; i++) {
						if (!listOfBrends.useTagName) {
							if (n[i].className == listOfBrends.elementClassName)
								count++;
						} else {
							if (listOfBrends.tagName.length > 0) {
								if (n[i].tagName == listOfBrends.tagName)
									count++;
							}						
						}					
					}
				}
				listOfBrends.elementCount = count;
				listOfBrends.width = listOfBrends.elementWidth * count;
				if (count > 0) {
					$("#" + listOfBrends.containerId).css("width", listOfBrends.width + "px");
					$("#" + listOfBrends.leftArrowId).bind("click",function() {
						//alert('left');
						listOfBrends.moveBack();
					});
					$("#" + listOfBrends.rightArrowId).bind("click",function() {
						//alert('right');
						listOfBrends.moveForward();
					});
				}
				if (count < 6) {
					$("#"+listOfBrends.rightArrowId).css("opacity", .5);
					$("#"+listOfBrends.rightArrowId).css("cursor", "default");
				}
				$("#"+listOfBrends.leftArrowId).css("opacity", .5);
				$("#"+listOfBrends.leftArrowId).css("cursor", "default");
			}
		}
	},
	//function return width for container
	getWidth: function() {
		
	},
	//function move list left
	moveForward: function() {
		if ((listOfBrends.width + listOfBrends.left)!=(listOfBrends.showElementCount*listOfBrends.elementWidth)) {
			listOfBrends.left -= listOfBrends.elementWidth;
			$("#"+listOfBrends.containerId).animate({marginLeft: listOfBrends.left+"px"}, 700, "swing", function() {
				if ((listOfBrends.width + listOfBrends.left)==(listOfBrends.showElementCount*listOfBrends.elementWidth)) {
					$("#"+listOfBrends.rightArrowId).css("opacity", .5);
					$("#"+listOfBrends.rightArrowId).css("cursor", "default");
				}
				if (listOfBrends.left!=0) {
					$("#"+listOfBrends.leftArrowId).css("opacity", 1);
					$("#"+listOfBrends.leftArrowId).css("cursor", "pointer");
				}
			});
			//$("#"+listOfBrends.containerId).css("left",-107+"px");
		}
	},
	//function move list right
	moveBack: function() {
		if (listOfBrends.left!=0) {
			listOfBrends.left += listOfBrends.elementWidth;
			$("#"+listOfBrends.containerId).animate({marginLeft: listOfBrends.left+"px"}, 700, "swing", function() {
				if (listOfBrends.left==0) {
					$("#"+listOfBrends.leftArrowId).css("opacity", .5);
					$("#"+listOfBrends.leftArrowId).css("cursor", "default");
				}
				if ((listOfBrends.width + listOfBrends.left)!=(listOfBrends.showElementCount*listOfBrends.elementWidth)) {
					$("#"+listOfBrends.rightArrowId).css("opacity", 1);
					$("#"+listOfBrends.rightArrowId).css("cursor", "pointer");
				}
			});
		}
	},
	//function check scroll position and hide arrows
	checkPosition: function() {
		
	}
}








jQuery.fn.setWait = function(options) {
	this.html('<div class="waiticon"></div>');
};

jQuery.fn.setMessage = function(options) {
	this.html('<div id="messageS1" style="display:none;">' + options.message + '</div>');
	$('div#messageS1').show('fast');
	
	if (options.timeout){
		setTimeout(function(){
			$('div#messageS1').hide('fast');
		}, options.timeout);
	};
		
};