

/******************* sliding boxes for the products  *************************/

var conH= 0;
		var conW = 0;
		var wrap = 1;
			
		
			var Nimages = 0;//starts at 0 so 0 = 1
	
			var cur_image = 1;
			function showCaption(cur_image)
			{
				
				// see if there is a caption on the image
						var caption = $("#slider_img_"+cur_image).attr('alt');
						
						if (caption !='' && caption !='undefined')
						{
								
								
								if ($('#caption_content').css('display')!='none')
								{
									
									
									
								}
								
								//$('#caption_content').slideUp(100).delay(1000).html('<p>'+caption+'</p>').slideDown(500);
								
								
								$('#caption_content').slideUp(500).delay(1000).queue(function(next){
												  $(this).html('<p>'+caption+'</p>');
												  next();
											}).slideDown(500);
								
								
								
							
						}
						else
						{
							
							$('#caption_content').slideUp(500);
							
						}
				
				
				
			}//end function
			
			
			
			
	
			function showNext(dir)
			{	
			
		
				var error = 0
				
						$('#slides_container div').each(function(index) {	
							
								
							var thisM = $(this).css('margin-left');
							//alert('current m argin: '+thisM)
								thisM = parseInt(thisM.substring(0,thisM.indexOf('px')));
									
									 if (dir==1)
								 {
								 	//moving elements towards the left
										
										thisM = (thisM - parseInt(conW)) + 'px' ;
										
										
										
										if (cur_image == Nimages){error=1;
										
										
											if (wrap ==1)
											{
													thisNM=0;
											
													$('#slides_container div').each(function(index) {
													
																
																$(this).animate({
															
															 marginLeft: thisNM+'px',
															 top:'0px'
															
														  }, 1000, function() {
															// Animation complete.
														  });
															thisNM = thisNM + conW;
													
													});
					
											cur_image = 1;
											showCaption(cur_image);
											
											}//end if wrap
											
										
											}//end of if error
										
								}
								else
								{
								//moving elements towards the rigth
										
										thisM = (parseInt(thisM) + parseInt(conW)) + 'px' ;
										
										
										if (cur_image == 1){error=1}
								}	
									
									
									
									if (error ==0)
									{	
									//alert('new margin: ' + thisM);
									
													$(this).animate({
												
												 marginLeft: thisM,
												 top:'0px'
												
											  }, 800, function() {
												// Animation complete.
											  });
												
								}
									
									
						});//end loop
								 
					if (error ==0)
					{	
					
							if (dir==1)
								 {
								 	
										
										cur_image++;
								}
								else
								{
								
										cur_image--;
								}	
				
						showCaption(cur_image);
				
					}
					
					
					var progress ='';
					//show progress
					for (i=0;i<Nimages;i++)
					{
							
							if ((i+1) == cur_image){progress = progress + '<div class="progress active"></div>';}
							else {progress = progress + '<div class="progress inactive"></div>';}
							
					
					
					}//closes for loop
					
					
					//show the progress bar
					$('#slide_progress').html(progress);
					
						
			}//end function
			
			function getSliderReady()
			{
					
					Nimages = 0;
					cur_image = 1;
					
					//get the container width and height
					conH = String($('#slides_container').css('height'));
					conH = parseInt(conH.substring(0,conH.indexOf('px')));
					conW = String($('#slides_container').css('width'));
					conW = parseInt(conW.substring(0,conW.indexOf('px')));
					

					//$('#slides_container').css('width')
					
					//set all sub containers the same width
					//$('#slides_container div').css({'width':''+conW+'px','height':''+conH+'px'})
					
					var marg = 0;//starting margin
					
					
					var progress = '';
					$('#slides_container div').each(function(index) {
					
							
							
							if (index==0){progress = '<div class="progress active"></div>';}
							else
							{
							
							progress = progress + '<div class="progress inactive"></div>';
							}
					
					
					
							//image_size[index] = new Array(,$(this).find('img').attr('height'));
					
							//resize the images at a suitable size
							
							var thisW = parseInt($(this).find('img').attr('width'));
							var thisH = parseInt($(this).find('img').attr('height'));
							
							//alert('original width: ' + thisW + ' original height: ' + thisH + ' ( height direct: '+$(this).find('img').height()+')');
							
							//alert('original width: ' + thisW + ' oringal height: ' + thisH)

							
							
							var ratio =0;
							
							var newW = thisW;
							var newH = thisH
							//check if the image is too high first
							if (newH > conH)
							{
									//find the ration
									ratio = thisH / conH;
										newW = parseInt(thisW / ratio);
										newH = parseInt(thisH / ratio)
								
							}
							
							if (newW > conW)
							{
							//the image is too wide, we reduce
							ratio = thisW / conW;
									newW = parseInt(thisW / ratio);
									newH = parseInt(thisH / ratio)
							
							
							
							}
							//center the image
							var marginL = (conW - newW) / 2;
							var marginT = (conH - newH) / 2;
							
						
							//css resize the image
							//alert('new widht: ' + newW + 'new height: ' + newH)
							//$(this).find('img').css({'width':+newW+'px','height':+newH+'px','margin-left':+marginL+'px','margin-top':+marginT+'px'});
							//add an id for the later use
								$(this).find('img').attr('id','slider_img_'+(Nimages + 1));
						
								$(this).find('img').animate({
												
												 width: newW+'px',
												 height: newH+'px',
												 marginLeft: marginL+'px',
												 marginTop: marginT+'px'
												 
												
											  }, 500, function() {
												// Animation complete.
											  });
						
						
						
							//check the image size
							//alert('width now is: ' +$(this).css('width'))
							
							
							//position the div tag
							 //$(this).css('margin-top',+con_top+'px');
							var con_top = '0px';
							if (index!=0){con_top ='-' + conH + 'px';}
							$(this).css('margin-top',''+con_top+'');
							
							
							$(this).css('margin-left',+marg+'px');
							marg = marg+ conW;
							
							Nimages++;
							
   			
 					 });
					$('#slides_container').css('overflow','hidden');
					
					//show the progress bar
					$('#slide_progress').html(progress);
					
		
			showCaption(1);
					
					
			}//end function
			
/********************************* end slider  ****************************/


/*************************  HIGHLIGHTING CURRENT PAGE  **************************/
$(document).ready(function() {


			/**********************************************************************************************/
			
			/*   ATTENTION, FOR THIS SCRIPT TO WORK YOU MUST SET THE HREF WITHIN THE LINK TO A FULL URL    */
			/*   FOR INSTANCE http://mydomain.com/page1.html AS OPPOSED TO  page1.html                     */
		//set the ID of the menu
			
/*				//current location
			var href = jQuery(location).attr('href');
		
		//REPEAT THE SCRIPT BELOW IF YOU WANT THIS TO WORK ON SEVERAL MENUS
		$('#top_nav li a').each(function(index) {
   				
						if ($(this).attr('href')== href)
						{
									$(this).addClass('top_nav_on');
									$(this).parent().addClass('top_nav_li_on');
						}//end if
							
	  			});//end loop
		
		
*/	

$(document).ready(function() {

	$("#nav li ul").hover(
  function () {$(this).prev().addClass('nav_li_on');}, 
  function () {$(this).prev().removeClass('nav_li_on'); }
	);
});



					
});







/*******************
Cufon
******************/

Cufon.replace('#banner_left p', {textShadow: '#1c1f95 1px 1px'});
Cufon.replace('.cuf-replace', {textShadow: '#042151 1px 1px', hover: true});
Cufon.replace('#banner p', {textShadow: '#1c1f95 1px 1px'});


/*******************
Cufon
******************/

function greyPage()
		{
			
			
		
			$("#grey_layer").css('height',$(document).height()+'px');
			$("#grey_layer").css('opacity','0.6');
			$("#grey_layer").fadeIn(1500)
			
			
			
			
			}


		function closeP()
			{
			
			  $("#full_detail").fadeOut("slow");
			  $("#grey_layer").hide();
			 window.document.getElementById("full_detail").innerHTML ='';
			
			}
		
		
		function showProduct(id)
		{
		 
		 greyPage();

		 //get the top and left positions we need to centre
					
						
							var top = $(window).scrollTop() + 50;
						
					
				
				
				
				
				
				window.document.getElementById("full_detail").style.top = top + 'px';//place the layer
				
				  $("#full_detail").fadeIn(2000);
				  
				 	 
				 
		  window.document.getElementById("full_detail").innerHTML = '<img src="http://www.flowebdesign.ie/library/ajax-loader2.gif" alt="Please wait" width="16" height="16" />&nbsp;&nbsp;&nbsp; Please wait while the detail is loading';
				 
				 
				 
				 
				 
				 
				 function callAjax(){
					 
					 $.ajax({
				
						type: "GET",
						url: "ssi/ajax_prod_detail.asp",
						data: {prodId: id},
						success: function(dataBack){
												
												
												var content = dataBack.split('*END-OF*');
												
												
												window.document.getElementById("full_detail").innerHTML = '<div style="margin-left: 720px;"><a href="javascript:closeP()"><img src="http://www.sesco.ie/library/button_close_green.png" alt="Close the window" border="0" /></a></div>' + content[0] + '<br /><a href="javascript:closeP()"><img src="http://www.sesco.ie/library/button_close_green.png"  alt="Close the window" border="0" /></a>';
												
												getSliderReady();
												
											}
				
				
				
				
				});
					 
				 }//end of call ajax
				 
				 
				 
				 
				 
				 
				 
				 
				 //see if we need to preload images
				 var imgs = $('#all_imgs_'+id).html();
				 
				 
				 if (imgs!='')
				 {
					 //need to preload images first
					 function moveN()
										{
																			
											callAjax();
											
																		
																		
											}
																		
																		
																			function _loadimages(imgArr) {
																				//Keep track of the images that are loaded
																				var imagesLoaded = 0;
																				 //alert(imagesLoaded);
																				function _loadAllImages(){
																					//Create an temp image and load the url
																					var img = new Image();
																					$(img).attr('src',imgArr[imagesLoaded]);
																					if (img.complete || img.readyState === 4) {
																						// image is cached
																						imagesLoaded++;
																						//Check if all images are loaded
																						if(imagesLoaded == imgArr.length) {
																							//If all images loaded do the callback
																							moveN();
																							//alert('images loaded: '+imagesLoaded);
																						} else {
																							//If not all images are loaded call own function again
																							_loadAllImages();
																						}
																					} else {
																						$(img).load(function(){
																							//Increment the images loaded variable
																							imagesLoaded++;
																							//Check if all images are loaded
																							if(imagesLoaded == imgArr.length) {
																								//If all images loaded do the callback
																								moveN();
																								//alert('images loaded: '+imagesLoaded);
																							} else {
																								//If not all images are loaded call own function again
																								_loadAllImages();
																							}
																						});
																					}
																				};		
																				_loadAllImages();
																			}	
																	
																	
																	
																	imgs = imgs.split(',');
																	
																	_loadimages(imgs);
																	
																														
													
													
													
													
													
					 
					 
				 }
				 else
				 {
					//there is only one image, no need to preload 
					
									  //call ajax when the function is called
						callAjax();
					 
				 }
				 
				 
				 
				 
				 
				 
				 //then call the detail

				  
				  
			
		 
		 
		 
		 
		 //alert('product '+ id)
		 
		 
		 }//end function




$(document).ready(function() {	
	

	$('.moredetail').click(function() {
									
	var id = $(this).attr('id');
	
	id = id.substring(6,id.length)
  		
  showProduct(id);
  return false;
  
  
  			
});


});



emai = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
function sendM() {
	
	
	//alert('function')
		
		
		
		var error = 0
		var errorM = '';
		
	if (document.form_side1.name.value==""){
                errorM = errorM + "Please enter your name\n";
                error=1;
        }
		
		

	if (!emai.test(document.form_side1.email.value)){
	 errorM = errorM + "Please enter a valid email address\n";	
	error=1;
        }
		
if (document.form_side1.message.value==""){
                 errorM = errorM +  "Please enter a message\n";
               error=1;
        }
		
		if (error ==1){alert('Please review the following error(s)\n\n'+ errorM);}
		else
		{// no error, we send
			
			//semi hide the button
			$("#but1").css('opacity','0.25');
			
			
							$.ajax({
				
						type: "POST",
						url: "ssi/send_sideform.asp",
						data: {name: document.form_side1.name.value,email:document.form_side1.email.value,message:document.form_side1.message.value},
						success: function(dataBack){
												
												if (dataBack==1)
												{
													
													document.form_side1.name.value='';
													document.form_side1.email.value='';
													document.form_side1.message.value='';
													alert("Thank you, your enquiry has been sent.\nWe will respond shortly.");
													$("#but1").css('opacity','1');
												}
											},
											error: function(x,e){
																if(x.status==0){
																alert('You are offline!!\n Please Check Your Network.');
																}else if(x.status==404){
																alert('Requested URL not found.');
																}else if(x.status==500){
																alert('Internel Server Error.');
																}else if(e=='parsererror'){
																alert('Error.\nParsing JSON Request failed.');
																}else if(e=='timeout'){
																alert('Request Time out.');
																}else {
																alert('Unknow Error.\n'+x.responseText);
																}
															}
				
				
				
				
				});
			
			}//end no error

}//end function









function sendM2() {
	
		
		var error = 0
		var errorM = '';
		
	if (document.form_side2.name_2.value==""){
                errorM = errorM + "Please enter your name\n";
                error=1;
        }
		
		

	
		
if (document.form_side2.tel_2.value==""){
                 errorM = errorM +  "Please enter a phone number\n";
               error=1;
        }
		
		if (error ==1){alert('Please review the following error(s)\n\n'+ errorM);}
		else
		{// no error, we send
			
			//semi hide the button
			$("#but2").css('opacity','0.25');
			
							$.ajax({
				
						type: "POST",
						url: "ssi/send_sideform2.asp",
						data: {name: document.form_side2.name_2.value,tel:document.form_side2.tel_2.value},
						success: function(dataBack){
												
												if (dataBack==1)
												{
													
													document.form_side2.name_2.value='';
													document.form_side2.tel_2.value='';
													
													alert("Thank you, your phone call request has been sent.\nWe will call you shortly.");
													
														$("#but2").css('opacity','1');
												}
											},
											error: function(x,e){
																if(x.status==0){
																alert('You are offline!!\n Please Check Your Network.');
																}else if(x.status==404){
																alert('Requested URL not found.');
																}else if(x.status==500){
																alert('Internel Server Error.');
																}else if(e=='parsererror'){
																alert('Error.\nParsing JSON Request failed.');
																}else if(e=='timeout'){
																alert('Request Time out.');
																}else {
																alert('Unknow Error.\n'+x.responseText);
																}
															}
				
				
				
				
				});
			
			
				
		}//end no error

}//end function








// Make the dropdown work

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


			
