// JavaScript Document
/********************************************************************************************
*																							*
*	copyright itHomepage Ltd, 2009/2010														*
*																							*
*********************************************************************************************
*																							*
*	This is the standard javascript 														*
*																							*
********************************************************************************************/
/********************************************************************************************
*																							*
*	this function is an automatic slide show												*
*																							*
********************************************************************************************/
function startup(div,url,freq) { 
		new PeriodicalExecuter(function() { 
		new Effect.Fade(div, { // the id of the <DIV> containing the photos 
		  duration: 1, 
		  fps: 50, 
		  afterFinish: function() { 
			new Ajax.Updater(div,url, { // URL for next <IMG> tag 
			  asynchronous: true, 
			  onSuccess: function() { 
				new Effect.Appear(div, {
				  duration: 1,
				  fps: 50,
				  queue:'end'
            })
          } 
        }) 
      } 
    }) 
  }, freq) // change image every 10 seconds 
}

function Album(div) { 
	this.div = div;
	this.startup = startup;
}
function init()
{
	sb1 = new Album();													// This is sidebar1 slide show
	sb1.startup('wearit', '/index.php/slideshow/sidebar1', 15);
	if ($('child')){
		childshow = new Album();
		childshow.startup('child', '/index.php/slideshow/child', 30);	// slideshow for childrens costumes
	}
	if($('adult')){
		adultshow = new Album();
		adultshow.startup('adult', '/index.php/slideshow/adult', 20);	// slideshow for childrens costumes
	}
	if($('fancydress')){
		adultshow = new Album();
		adultshow.startup('fancydress', '/index.php/slideshow/fancydress', 20);	// slideshow for childrens costumes
	}
	if($('balloons')){
		adultshow = new Album();
		adultshow.startup('balloons', '/index.php/slideshow/balloons', 20);	// slideshow for childrens costumes
	}
	var images = $$('img.buynow');
		images.each(
					function(image) {
						image.observe('click', addtocart);
					}
					);
	var	k = $('keywords');
		k.observe('focus', cleartext);
}
/********************************************************************************************
*																							*
*	This is the add the item to the cart													*
*																							*
********************************************************************************************/
function addtocart(event)
{
	var formname = event.element().name;
	var f = $(formname);
	var qty=f.qty.value;
	var productcode = f.productcode.value ;
	var params = {
		"qty":qty,
		"productcode":productcode
	}
	var request = new Ajax.Updater(
		'cartinfo',
		"/index.php/shop/addtocart/",
		{
			parameters:params
		}
	);
}
/********************************************************************************************
*																							*
*	This clear cart functio																	*
*																							*
********************************************************************************************/
function clearcart()
{
	var request = new Ajax.Updater(
		'cartinfo',
		"/index.php/shop/clearcart/",
		{
		}
	);
}
/********************************************************************************************
*																							*
*	This clears any text in the keywords input box											*
*																							*
********************************************************************************************/
function cleartext()
{
	var k = $('keywords');
		k.value = '';
}
/********************************************************************************************
*																							*
*	end of progam																			*
*	/js																						*
*																							*
********************************************************************************************/
