	$(function(){
	var $azs03_pane = $("#az_scroll03");
	var $azs03_pane_pos = $azs03_pane.position();
	var $azs03_paneW = $azs03_pane.innerWidth();
	var $azs03_callout = $("#az_scroll03_callout");
	var azs03_data = new Array();
	var stopscroll = false;
	var hoveredID = '';
	
	var azs03 = {
		params: params,
		mod_imgpath: 'images/azscroll03/',
		imageW: '',
		imageH: '220',
		xmlsrc: 'azscroll03_loader.php',
		imgpath: '',
		loading1: 'images/azscroll03/az_scroll03_loading.gif',
		loading2: 'images/azscroll03/ajax_loader2.gif',
		noimage: 'noimage.gif',
		time: '',
		sortby: 'name',
		sort_order: 'asc',
		limitstart: 0,
		limit: 10,
		result: 0,
		total: 0
	};
	
	azs03_retrieveContent = function(){
		$.ajax({
			url: azs03.xmlsrc,
			type: "get",
			dataType: "xml",
			data: azs03.params+"&task=getproducts&sort="+azs03.sortby+"&sortorder="+azs03.sort_order+"&limitstart="+azs03.limitstart+"&limit="+azs03.limit,
			error: function(){
				$("#az_scroll03").html('Error loading XML data');
			},
			success: function(xml){
				var gallery = $(xml).find("gallery");
				
				azs03.sortby = gallery.attr("sortby");
				azs03.sort_order = gallery.attr("sortdir");
				azs03.limitstart = gallery.attr("limitstart");
				azs03.result = gallery.attr("result");
				azs03.total = gallery.attr("total");
				azs03.imgpath = gallery.attr("path");
				
				$("product", xml).each(function(i){
					azs03_data[i] = new Array();
					azs03_data[i]['id'] = $("id", this).text() ? $("id", this).text() : 0;
					azs03_data[i]['title'] = $("title", this).text() ? $("title", this).text() : "no data";
					azs03_data[i]['desc'] = $("description", this).text()? $("description", this).text() : "no data";
					azs03_data[i]['image'] = $("image", this).text() ? $("image", this).text() : azs03.noimage;
					azs03_data[i]['price'] = $("price", this).text() ? $("price", this).text() : 0;
					azs03_data[i]['sprice'] = $("sprice", this).text() ? $("sprice", this).text() : 0;
					azs03_data[i]['cart'] = $("cart", this).text() ? $("cart", this).text() : 0;
					azs03_data[i]['url'] = $("url", this).text() ? $("url", this).text() : "";
				});
				azs03_parseDisplay();
			}
		});
	};
	
	azs03_parseDisplay = function() {
		var azs03_html = '';
		var imgDimension = (azs03.imageW ? 'width="' + azs03.imageW + '" ' : '') + (azs03.imageH ? 'height="' + azs03.imageW + '" ' : '');
		$(azs03_data).each(function(i, data){
			imgpath = azs03.imgpath + data['image'];
			azs03_html += '<a href="' + data['url'] + '"><img id="' + i + '" alt="" src="' + imgpath + '" border="0" ' + imgDimension + '></a>';
		});
		
		$azs03_pane.html(azs03_html);
		
		$azs03_pane.imageScroller({
			loading:"Wait please...", 
			speed: "5000"
		});
		
		$("img", $azs03_pane).hover(
			function() {
				clearTimeout(azs03.timer);
				hoveredID = this.id;
				popupTimer = setTimeout('calloutBox("show", ' + this.id + ')', 200);
			},
			function() { azs03.timer = setTimeout('calloutBox("hide")', 300); }
		);
		
		$azs03_callout.hover(
			function() { clearTimeout(azs03.timer); },
			function() { azs03.timer = setTimeout('calloutBox("hide")', 300); }
		);
	};
	
	calloutBox = function(action, id){
		if(action=="show") {
			var $obj = $("img#"+id, $azs03_pane);
			var $pos = $obj.position();
			posY = $pos.top + parseInt(($obj.innerHeight() - $azs03_callout.height()) / 2);
			
			if($pos.left < 450){ 
				$azs03_callout.removeClass("az_scroll03_calloutRight");
				$azs03_callout.addClass("az_scroll03_calloutLeft");
				posX = $pos.left + parseInt($obj.innerWidth()/2);				
			}else if($pos.left >= ($azs03_paneW-parseInt($obj.innerWidth()/2))){
				$azs03_callout.removeClass("az_scroll03_calloutLeft");
				$azs03_callout.addClass("az_scroll03_calloutRight"); 
				posX = parseInt($pos.left - $azs03_callout.width()) + parseInt(($azs03_paneW-$pos.left)/2);
			}else{ 
				$azs03_callout.removeClass("az_scroll03_calloutLeft");
				$azs03_callout.addClass("az_scroll03_calloutRight"); 
				posX = $pos.left - parseInt($azs03_callout.width() - ($obj.innerWidth()/2));
			}
			
			if(stopscroll==false) $azs03_pane.trigger("stopScroll");
			$azs03_callout.css({'top': posY+'px', 'left': posX+'px'}).fadeIn(600).html(getDescription(azs03_data[id]));
		}else{
			if(stopscroll==false) $azs03_pane.trigger("startScroll");
			$azs03_callout.fadeOut('fast');
			hoveredID = '';
		}
	}
	
	getDescription = function(data){
		var html = '';
		imgpath = azs03.imgpath + data['image'];
		pdesc = data['desc'].length > 80 ? data['desc'].substr(0,80)+'...' : data['desc'];
		html += '<table id="az_scroll03_desc_table" border="0" width="266" cellspacing="0" cellpadding="0"><tr>' + 
				'<td id="az_scroll03_img_box"><img src="' + imgpath + '" border="0" width="60" alt=""></td>' + 
				'<td id="az_scroll03_desc_box">' + 
				'<div class="az_scroll03_title">' + data['title'] + '</div>' + 
				'<p class="az_scroll03_desc">' + pdesc + '</p>' + 
				'<div class="az_scroll03_price">' + getPrice(data['price'], data['sprice']) + '</div>' + 
				'<div class="az_scroll03_button">' + 
				  '<a href="' + addtocarturl + '&amp;products_id=' + data['id'] + '"><img src="' + azs03.mod_imgpath + 'addtocart.png" border="0" width="111" alt=""></a>' + 
				'</div>' + 
				'</td>' + 
				'</tr></table>';
		
		return html;
	}
	
	getPrice = function(price, sprice){
		if(!sprice == 0){
			price = '<s>' + price + '</s> ' + sprice;
		}
		return price;
	}
	
	$("#az_scroll03_control").click(function(){
		if(this.title == 'pause'){
			$(this).attr({title: "play"});
			$(this).addClass("az_scroll03_play");
			$azs03_pane.trigger("stopScroll");
			stopscroll = true
		}else{
			$(this).attr({title: "pause"});
			$(this).removeClass("az_scroll03_play");
			$azs03_pane.trigger("startScroll");
			stopscroll = false
		}
	});
	
	azs03_retrieveContent();
});