// var to determine if the slidedown effect is in progress

var lousliding = false;





function change_img_to(link, to)

{

	

	image2 = link.firstChild;	

	image2.src='images/'+to;





}



function setSlideTrue()

{

	lousliding = true;

}



function setSlideFalse()

{

	lousliding = false;

}



function slideBar(id)

{

	//sliding = true;

	/*

	if(id=='id_collection_bar'){

		$('id_bags_bar').style.display='none';

		$('id_collection_bar').style.display='block';

	}

	if(id=='id_bags_bar'){

		$('id_collection_bar').style.display='none';

		$('id_bags_bar').style.display='block';

	}

	*/

	//alert(sliding);

	

	$(id).style.display = 'none';



	Effect.SlideDown(id, { duration: 0.3, beforeStart: setSlideTrue, afterFinish: setSlideFalse });



	

	/*

	if(id=='id_collection_bar')

	{

			loadPage('show_collection.php');

			return;

	}



	if(id=='id_bags_bar')

	{

		loadPage('show_accessories.php');

		return;

	}*/

	

	//sliding = false;

	//alert(sliding);

	return false;

}



// fades in / out an image

function opacity(id, opacStart, opacEnd, millisec) { 

    //speed for each frame 

    var speed = Math.round(millisec / 100); 

    var timer = 0; 



    //determine the direction for the blending, if start and end are the same nothing happens 

    if(opacStart > opacEnd) { 

        for(i = opacStart; i >= opacEnd; i--) { 

            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 

            timer++; 

        } 

    } else if(opacStart < opacEnd) { 

        for(i = opacStart; i <= opacEnd; i++) 

            { 

            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 

            timer++; 

        } 

    } 

} 



//change the opacity for different browsers 

function changeOpac(opacity, id) { 

    var object = document.getElementById(id).style; 

    object.opacity = (opacity / 100); 

    object.MozOpacity = (opacity / 100); 

    object.KhtmlOpacity = (opacity / 100); 

    object.filter = "alpha(opacity=" + opacity + ")"; 

} 





function gotoCollection()

{

	

	changeBackToPlain();

	



	



}



function changeBackToPlain()

{



	// fade out

	//opacity('content', 100, 0, 500);

	

	var content = document.getElementById('content');



	// change bg image

	content.style.backgroundImage= 'url(images/background.jpg)';



	// fade in

	//opacity('content', 0, 100, 500);

}



function loadPageAndRetractBars(page)

{	

	retractAllShopBars();

	loadPage(page)



}



function loadPage(page)

{

	changeBackToPlain();

	new Ajax.Updater('content', page, { method: 'get' });

	resetPaginationCounters();

}



function retractAllShopBars()

{

	

	if($('id_2nd_level_bar').style.display!='none')

			Effect.SlideUp($('id_2nd_level_bar'), { duration: 0.2 });

	if($('id_collection_bar').style.display!='none')

			Effect.SlideUp($('id_collection_bar'), { duration: 0.2 });

	if($('id_bags_bar').style.display!='none')

			Effect.SlideUp($('id_bags_bar'), { duration: 0.2 });

}



//////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////

var showHideCollectionImages = 0;

function resetPaginationCounters()

{

	//alert('resetting pag counters');

	showHideCollectionImages = 0;

	showHideCollectionItemImages = 0;

	showHideGalleryImages = 0;

}



function showHideCollectionImagesNext(maxPageNum)

{

	//alert('showHideCollectionImages = '+showHideCollectionImages);

	

	if((showHideCollectionImages+1)>=maxPageNum)

	{	

		return;  // no more image divs to view so return

	}

	

	eval('div_to_hide = id_'+showHideCollectionImages+'_img_div');

	

	$(div_to_hide).style.display='none';



	showHideCollectionImages++;



	div_to_show = 'id_'+showHideCollectionImages+'_img_div';

	

	$(div_to_show).style.display='block';	



	// change pag to show correct from to

	eval('pag_results_to_show = id_'+showHideCollectionImages+'_span_div');

	$('id_pagination').innerHTML = $(pag_results_to_show).innerHTML;

	

}



function showHideCollectionImagesPrev()

{

	

	if(showHideCollectionImages==0)

		return;

	

	eval('div_to_hide = id_'+showHideCollectionImages+'_img_div');

	

	$(div_to_hide).style.display='none';



	showHideCollectionImages--;



	div_to_show = 'id_'+showHideCollectionImages+'_img_div';



	$(div_to_show).style.display='block';



	// change pag to show correct from to

	eval('pag_results_to_show = id_'+showHideCollectionImages+'_span_div');

	$('id_pagination').innerHTML = $(pag_results_to_show).innerHTML;



}



function showHideCollectionGoto(pageNumber, currentlyOn)

{

	//alert('gotoPage = '+pageNumber+' currentlyon='+currentlyOn);



	showHideCollectionImages = pageNumber;



	eval('div_to_hide = id_'+currentlyOn+'_img_div');

	

	$(div_to_hide).style.display='none';	



	div_to_show = 'id_'+showHideCollectionImages+'_img_div';



	$(div_to_show).style.display='block';



	// change pag to show correct from to

	eval('pag_results_to_show = id_'+showHideCollectionImages+'_span_div');

	$('id_pagination').innerHTML = $(pag_results_to_show).innerHTML;



}



/////////////////////////////////////////////////////////////////////////////

//////////////// same 3 functions as above but for the drill down to view collection iems

var showHideCollectionItemImages = 0;



function showHideCollectionItemImagesNext(maxPageNum)

{

	//alert('showHideCollectionItemImages = '+showHideCollectionItemImages);

	

	if((showHideCollectionItemImages+1)>=maxPageNum)

	{	

		return;  // no more image divs to view so return

	}

	

	eval('div_to_hide = id_'+showHideCollectionItemImages+'_img_div');

	

	$(div_to_hide).style.display='none';



	showHideCollectionItemImages++;



	div_to_show = 'id_'+showHideCollectionItemImages+'_img_div';

	

	$(div_to_show).style.display='block';	



	// change pag to show correct from to

	eval('pag_results_to_show = id_'+showHideCollectionItemImages+'_span_div');

	$('id_pagination').innerHTML = $(pag_results_to_show).innerHTML;

	

}



function showHideCollectionItemImagesPrev()

{

	

	if(showHideCollectionItemImages==0)

		return;

	

	eval('div_to_hide = id_'+showHideCollectionItemImages+'_img_div');

	

	$(div_to_hide).style.display='none';



	showHideCollectionItemImages--;



	div_to_show = 'id_'+showHideCollectionItemImages+'_img_div';



	$(div_to_show).style.display='block';



	// change pag to show correct from to

	eval('pag_results_to_show = id_'+showHideCollectionItemImages+'_span_div');

	$('id_pagination').innerHTML = $(pag_results_to_show).innerHTML;



}



function showHideCollectionItemGoto(pageNumber, currentlyOn)

{

	//alert('gotoPage = '+pageNumber+' currentlyon='+currentlyOn);



	showHideCollectionItemImages = pageNumber;



	eval('div_to_hide = id_'+currentlyOn+'_img_div');

	

	$(div_to_hide).style.display='none';	



	div_to_show = 'id_'+showHideCollectionItemImages+'_img_div';



	$(div_to_show).style.display='block';



	// change pag to show correct from to

	eval('pag_results_to_show = id_'+showHideCollectionItemImages+'_span_div');

	$('id_pagination').innerHTML = $(pag_results_to_show).innerHTML;



}



function gotoCollectionItems(collectionId, groupType)

{

	// ajax load items

	showHideCollectionItemImages = 0; //reset paginatino var so that will work ok ?

	changeBackToPlain();

	new Ajax.Updater('content', 'show_collection_items.php', { method: 'get', parameters: {collection_id: collectionId, group_type: groupType}  });

	resetPaginationCounters();

}





function gotoItem(itemId, collection, collectionId, groupType)

{

	// ajax load items

	changeBackToPlain();

	new Ajax.Updater('content', 'show_item.php', { method: 'get', parameters: {item_id: itemId, collection: collection, collection_id: collectionId, group_type: groupType}  });

	resetPaginationCounters();

}



///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////



/* gallery images */

var showHideGalleryImages = 0;



function showHideGalleryImagesNext(maxPageNum)

{

	

	//alert('on next function');

	if((showHideGalleryImages+1)>=maxPageNum)

	{	

		return;  // no more image divs to view so return

	}

	

	//alert('about to hide this div '+'id_'+showHideGalleryImages+'_img_div');

	eval('div_to_hide = id_'+showHideGalleryImages+'_img_div');

	

	$(div_to_hide).style.display='none';



	showHideGalleryImages++;

	

	//alert('to show this div '+'id_'+showHideGalleryImages+'_img_div');

	div_to_show = 'id_'+showHideGalleryImages+'_img_div';

	

	$(div_to_show).style.display='block';	



	// change pag to show correct from to

	eval('pag_results_to_show = id_'+showHideGalleryImages+'_span_div');

	//alert('div to be updated ='+' id_'+showHideGalleryImages+'_span_div');

	//alert('html to echo'+$(pag_results_to_show).innerHTML);

	$('id_pagination').innerHTML = $(pag_results_to_show).innerHTML;

	

}



function showHideGalleryItemGoto(pageNumber, currentlyOn)

{



	//alert('gotoPage = '+pageNumber+' currentlyon='+currentlyOn);



	showHideGalleryImages = pageNumber;



	eval('div_to_hide = id_'+currentlyOn+'_img_div');

	

	$(div_to_hide).style.display='none';	



	div_to_show = 'id_'+showHideGalleryImages+'_img_div';



	$(div_to_show).style.display='block';



	// change pag to show correct from to

	eval('pag_results_to_show = id_'+showHideGalleryImages+'_span_div');

	$('id_pagination').innerHTML = $(pag_results_to_show).innerHTML;



}



function showHideGalleryImagesPrev()

{

	//alert('showHideGalleryImages = '+showHideGalleryImages);

	if(showHideGalleryImages==0)

		return;

	

	

	eval('div_to_hide = id_'+showHideGalleryImages+'_img_div');

	//alert('about to hide ='+'id_'+showHideGalleryImages+'_img_div');

	$(div_to_hide).style.display='none';



	showHideGalleryImages--;



	div_to_show = 'id_'+showHideGalleryImages+'_img_div';

	//alert('about to display='+'id_'+showHideGalleryImages+'_img_div');

	$(div_to_show).style.display='block';



	// change pag to show correct from to

	eval('pag_results_to_show = id_'+showHideGalleryImages+'_span_div');



	//alert('pag div to be updated to this='+$(pag_results_to_show).innerHTML);

	$('id_pagination').innerHTML = $(pag_results_to_show).innerHTML;



}









/* end of gallery images */



var soomer = false;



function zoomImage(img)

{	

	//alert('img.width = '+img.width+'\nimg.height = '+img.height);

	if(zoomThreadBusy)

		return false;



	debugger;

	

	if(img.width > 240)

		return false;

	

	if(img.name == 'zoomed')

		return false;



	zoom(img, 200); 



	img.name = 'zoomed';



	return false;

}



function zoomImageBack(img)

{

	//alert('img.width = '+img.width);

	if(zoomThreadBusy)

		return false;



	if(img.width < 120  || img.width == 120) // its already zoomed stop it from zooming anymore

	{

		console.log('img is already zoomed');

		return false;

	}

	

	if(img.name != 'zoomed')

		return false;

	

	//alert('mouse out img name = '+img.name);

	

	zoom(img, 50); 



	img.name = 'not_zoomed';



	return false;

	

}

var zoomThreadBusy = false;



function zoom(img, scale)

{

	zoomThreadBusy = true;

	

	new Effect.Scale(img, scale)



	zoomThreadBusy = false;

}



function addItem(id)

{

	// 	





	new Ajax.Updater('addedItem', 'add_item.php', 

		{ 

			method: 'post', parameters: {product_id: id}  , onComplete: function(){ updateCart() } 

		});

	

	

}



function updateCart()

{	

	new Ajax.Updater('id_top_cart_include', 'ajax_update_topcart.php', 

						{ 

							method: 'post'  , onComplete: function(){ showGotoCart() }

						}

					);

}



function showGotoCart()

{

	var answer = confirm("click Ok if you want to checkout or cancel to continue shopping.");

	if(answer)

		location.href="shopping_bag.php";





}


function deleteItem(id)

{	

	location.href='shopping_bag.php?itemaction=deleteitem&product_id='+id;	

}





function validateForm(contact_form)

{



	var passMail = false;

	var passEnq = false;

	var passName = false;
	
	if(contact_form.name.value!="")

		passName=true;

	if(contact_form.enquiry.value!="")

		passEnq=true;

	if(contact_form.email.value!="")

		passMail=true;



	if( !(passMail && passEnq && passName)){

		alert('name, email and enquiry must be filled in');

		return false;

	}


 	with (contact_form)
  	{
  		if (validate_email(contact_form.email,"Not a valid e-mail address")==false)
    		{contact_form.email.focus();return false;}
  	}

}



function validate_form(check_form)

{

	form_ok = false;



	error_message = "";

	if(!check_form.terms_check.checked)

		error_message += "terms must be agreed";

	else

		form_ok = true;



	

	if(check_form.fname.value=="" || check_form.address.value==""){

		error_message+="\nname and address must be entered";

		form_ok=false;

	}

	with (check_form.email)

	{

		apos=value.indexOf("@");

		dotpos=value.lastIndexOf(".");

		if (apos<1||dotpos-apos<2) 

		{

			

			error_message += "\nemail incorrect";

			form_ok =  false;

		}

		

	}



	if(!form_ok)

		alert(error_message);

	

	//alert('the form = '+form_ok);



	return form_ok;

	

	



}




function validate_email(field,alerttxt)

{



	with (field)

	{

		apos=value.indexOf("@");

		dotpos=value.lastIndexOf(".");

		if (apos<1||dotpos-apos<2) 

		{

			

			alert(alerttxt);		

			return false;

		}

		else 

		{

			return true;

		}

	}

}