/***** quick ***/
function animate_opacity(element,duration,start,finish) {
	glow.anim.css( element, duration, {"opacity": {from: start, to: finish}}).start();

}

function test_anim(){
	animate_opacity(".item_text","1","0.1","0.8");	
}
glow.ready(function() {
		if (homepage){
		var carousel6 = new glow.widgets.Carousel("#promo_carousel",{size: 1,theme:"dark",loop:true});
		setupListeners('#promo_carousel');
	}
		setupContact();
		glow.dom.get("#rounded-textbox").val("search here..."); 
		setupSearch();
		glow.anim.fadeOut(" .item_text", 1.5);
		lightBox();
});
	

function lightBox(){

	var img = glow.dom.get("#main_body .thumbnail a");
	img.attr("href", "javascript:void(0)");
	
	glow.events.addListener('.thumbnail a',  'click', function () {
		var img = glow.dom.get(this).get('img');
		var str = img.attr('src').toString();
		str = str.substr(0, str.indexOf('-150x150.jpg'));
		str = str + ".jpg";	
			var myOverlay = new glow.widgets.Overlay(contactMap, {
			  mask: new glow.widgets.Mask({color:"#343942"}),
			  anim: "fade",
			autoPosition: true,
				x: "30px",
			  y: "30px",
			width:'667px',
			closeOnEsc: true
			});
			var myOverlay = new glow.widgets.Panel(
			  glow.dom.create('<div  class="fixed" style="width:800px;height:800px"> <img src ="'+ str+  '" style="max-width:800px;max-height:800px" /></div>'), {
			      width:'1000px'
			    }
			);
			myOverlay.show();	
	});
	

    
	
	
}
function setupListeners(carousel) {
var carouselItems = glow.dom.get(carousel);
var hello = carousel  + " .item_text";
for ( var i in carouselItems )
{
	glow.events.addListener(carouselItems[i],  'mouseenter', function () {  animate_opacity(hello,"0.5","0","0.8")});
	glow.events.addListener(carouselItems[i],  'mouseleave', function () {	animate_opacity(hello,"0.5","0.8","0")});
	
}
}

function setupContact(){
contactMap = glow.dom.create('<div id="contactImage"><img   src="http://bricklanebikes.co.uk/wordpress/wp-content/uploads/2009/05/contactmap.png" title="contact map" /></div>');
var myOverlay = new glow.widgets.Overlay(contactMap, {
  mask: new glow.widgets.Mask({color:"#343942"}),
  x: "40%",
  y: "40%"
});
glow.events.addListener('#address',  'click', function () {myOverlay.show();});
glow.events.addListener('#address',  'mouseenter', function () {   	glow.dom.get(this).addClass('hover');});
glow.events.addListener('#address',  'mouseleave', function () {	glow.dom.get(this).removeClass('hover');	});

}
function setupSearch(){
	glow.events.addListener(glow.dom.get("#rounded-textbox"),'focus',function() {
	 		if (glow.dom.get("#rounded-textbox").val() == "search here..." ) {
			glow.dom.get("#rounded-textbox").val('');
			glow.dom.get("#rounded-textbox").removeClass("inactive");
			var quickfinder_anim = glow.anim.css("#rounded-textbox", 1.3, { "opacity": {from: "0.6", to: "1"}  });
	     	quickfinder_anim.start();
		 
	
			}   

		});
	
	
}	
