// JavaScript Document
window.addEvent('domready', function(){
var img = new Array();
	var cases = $$("#product_list li");
	cases.each(function(el){
		el.addEvents({
			'mouseenter':function(){this.addClass('over');},
			'mouseleave':function(){this.removeClass('over');}
		});
	});
	
	if($chk($('sel_category'))){
		$("sel_category").addEvent('change', function(){window.location.href = this.get('value');});
	}
	
	if($chk($('product_list'))){
		var images = document.getElementsByTagName('img');      
		for (var i=0; i<images.length; i++){         
			img[i] = images[i].getAttribute('src');
			if(img[i].indexOf("modules/product") > 0){
				images[i].onclick = function(){
					milkbox.initMilkbox();
					milkbox.openMilkbox(this.src,1)
				};
			}
		}
		/*var plist = $$("#product_list li");
		plist.each(function(el, i){
			var request = new Request.JSON({
				method: 'get',
				url: window.location.href + "?action=ajax_get_imgs&pid=" + el.get("id").replace("p", ""),
				onComplete: function(rJSON, response) {					
					var json = $H(JSON.decode(response, true));
					if(json["images"].length>0){
						var u = el.getElement('p[class=more]').getElement('a').getProperty('href');
						el.getElement('div[class=img]').getElement('img').fade('out').retrieve('tween').chain(function(){
							window.slides = Slides.start(el.getElement('div[class=img]'), json["images"], {showFor: 4000, transitionFor: 750, rel:el.get("id"), init_mb:false, target:u, link:true});
						});
					}
				},
				onException: function(headerName, value){console.log(value)},
				onFailure: function(xhr){console.log(xhr)}					
			}).send();												
		});*/
	}
	
	if($chk($('case_detail'))){	
		var images = document.getElementsByTagName('img');      
		for (var i=0; i<images.length; i++){         
			var img =images[i].getAttribute('src'); 
			if(img.indexOf("modules/product") > 0){
				images[i].onclick = function(){
					milkbox.initMilkbox();
					milkbox.openMilkbox(this.src,1)
				};
			}
		}
	
		/*var el = $("case_detail").getElement("div[class=img]");
		var request = new Request.JSON({
				method: 'get',
				url: window.location.href + "?action=ajax_get_imgs&pid=" + el.get("id").replace("p", ""),
				onComplete: function(rJSON, response) {					
					var json = $H(JSON.decode(response, true));
					el.getElement('img').fade('out').retrieve('tween').chain(function(){
						window.slides = Slides.start(el, json["images"], {showFor: 4000, transitionFor: 750, rel:el.get("id"), init_mb:true, link:true});
					});
				}
			}).send();					
		*/
	}
	
});
