//Style the text to be replaced with cufon
$(function() {
Cufon.replace('#header_container h4', {
				color: '-linear-gradient(#2e6784, #5aa3c8)', // Step 13 //#b9b9b9
				textShadow: '1px 1px rgba(255, 255, 255, 1)' // Step 12
			});
		   });



//Image Slider in content area on homepage
	
$(document).ready(function() {

	//Speed of the slideshow
	var speed = 5000;
	
	//You have to specify width and height in #slider CSS properties
	//After that, the following script will set the width and height accordingly
	$('#mask-gallery, #gallery li').width($('#slider-side').width());	
	$('#gallery').width($('#slider-side').width() * $('#gallery li').length);
	$('#mask-gallery, #gallery li, #mask-excerpt, #excerpt li').height($('#slider-side').height());
	
	//Assign a timer, so it will run periodically
	var run = setInterval('newsscoller(0)', 5000);	
	
	$('#gallery li:first, #excerpt li:first').addClass('selected');

	//Pause the slidershow with clearInterval
	$('#btn-pause').click(function () {
		clearInterval(run);
		return false;
	});

	//Continue the slideshow with setInterval
	$('#btn-play').click(function () {
		run = setInterval('newsscoller(0)', speed);	
		return false;
	});
	
	//Next Slide by calling the function
	$('#btn-next').click(function () {
		newsscoller(0);	
		return false;
	});	

	//Previous slide by passing prev=1
	$('#btn-prev').click(function () {
		newsscoller(1);	
		return false;
	});	
	
	//Mouse over, pause it, on mouse out, resume the slider show
	$('#slider-side').hover(
	
		function() {
			clearInterval(run);
		}, 
		function() {
			run = setInterval('newsscoller(0)', speed);	
		}
	); 	
	
});


function newsscoller(prev) {

	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
	var current_excerpt = $('#excerpt li.selected').length ? $('#excerpt li.selected') : $('#excerpt li:first');

	//if prev is set to 1 (previous item)
	if (prev) {
		
		//Get previous sibling
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');
		var next_excerpt = (current_excerpt.prev().length) ? current_excerpt.prev() : $('#excerpt li:last');
	
	//if prev is set to 0 (next item)
	} else {
		
		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
		var next_excerpt = (current_excerpt.next().length) ? current_excerpt.next() : $('#excerpt li:first');
	}

	//clear the selected class
	$('#excerpt li, #gallery li').removeClass('selected');
	
	//reassign the selected class to current items
	next_image.addClass('selected');
	next_excerpt.addClass('selected');

	//Scroll the items
	$('#mask-gallery').scrollTo(next_image, 800);		
	//$('#mask-excerpt').scrollTo(next_excerpt, 800);					
	
}



//top slider

	//starting the image slider
						
						
						$(document).ready(function(){	
												   $("#gallery-slider_img ul").fadeIn(2500);
							$("#gallery-slider_img").easySlider({
								auto: true, 
								continuous: true
							});
							
							
							
						});	


////////////****************************************** scripts         *//////////////

var menu_open =0;	

$(function(){ 
   
$("#main_nav").hover(
		function(){ 
		
						
					},
					function(){ 
					
					menu_open=0;
		
				$("#sublinks_container").slideUp("slow");
			
					}
					
					
			
			
			); 

});








			

			function hideMenu()
			{
					
					
					//$("#sublinks_container").slideUp("fast");
					for (i=0;i<6;i++)
					{
					
					$(".sublinks"+i+"").hide();
					
					}
			
			}
			
		
						
			function showMenu(tab)
			{		
					
					hideMenu();
					
					
					if (menu_open==0)
					{
					//open the layer
					
							
							$("#sublinks_container").slideDown("slow");
							menu_open=1;
					}
					
					
					
					//bring the new in 
						$(".sublinks"+tab+"").fadeIn("fast");
						
						
					
			}
			
			
			
			
			
			
			
		function closeMenu()
		{
			//closing the full menu
			
			
			
			if (event.srcElement.id == "main_nav_content") {
        			//do your stuff here
					hideMenu();
					$("#sublinks_container").slideUp("slow");
					//alert(event.srcElement.id)
				} else {
					//nevermind, don't do anything
				}

			
		}
			
			
			
			panel_open=0
			function openPanel()
			{
			
					
					if (panel_open==0){
					$("#login_panel").slideDown("slow");
					panel_open = 1;
					}
					else
					{
					$("#login_panel").slideUp("slow");
					panel_open = 0;
					}
					
					
			
			
			}
			
			
			
			
			
			
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//preload images
$(document).ready(function(){	
							
							
							MM_preloadImages('library/links_contact_f2.png','library/links_portfolio_f2.png');
							
							$('.next_link_place').fadeIn('slow');
							$('#port-list').hide();
							
							
						});	




	function showlogin(action)
	{
			
		//hide and show
		if (action==1)
		{
			$("#login2").slideUp('fast');
			$("#login1").slideDown('slow');
			
		}
		else
		{
					$("#login1").slideUp('fast');
			$("#login2").slideDown('slow');	
			
		}
		
		
		
	}



//open the request for a brochure
var br_open = 0
function reqBro()
{
	
	if (br_open==0)
	{
		
		br_open = 1;
		$("#brochure-req-layer").slideDown("slow");
		
	}
	else
	{
		$("#brochure-req-layer").slideUp("slow");
		br_open = 0;
	}
	
	
	
}



	function sendBro()
	{
		
		
		
		//call ajax when the function is called
				$.ajax({
				
						type: "POST",
						url: "http://www.flowebdesign.ie/bro-request-ajax.asp",
						data: {co_name:document.brochreq.co_name.value,name:document.brochreq.name.value,tel:document.brochreq.tel.value,add:document.brochreq.add.value,comment:document.brochreq.comment.value},
						success: function(dataBack){
												
												var result = dataBack.substring(0,1);
												
												if (result ==1){
														//email sent
														alert("Thank you, your request has been sent!\n\nWe endeavour to answer all enquiries within 1 business day.");
														document.brochreq.co_name.value='';
														document.brochreq.name.value='';
														document.brochreq.tel.value ='';
														document.brochreq.add.value='';
														document.brochreq.comment.value='';
														window.document.getElementById("bro-mess").innerHTML = '';
														
														$("#brochure-req-layer").slideUp("slow");
														br_open = 0;
														
														
												}
														
													else
													{
														alert("Sorry, some of the fields were not filled out\nPlease review the list at the top of the contact form.")
														window.document.getElementById("bro-mess").innerHTML = '<p>The following error occured: <ul>' + dataBack.substring(1,dataBack.length)+ '</ul>';
													}
												
												
												
												
											}
				
				
				
				
				});
		
		
		
		
		
		
	}//closing sendBro()




function openHelp(id)
{


var newwindow = window.open("https://secure.flowebdesign.ie/customers/help_window.asp?prodId="+ id +"","letterWin","width=350,height=350,scrollbars=yes,left=200,top=150");

 if (window.focus) {newwindow.focus()}

}

   $(function(){ 
$("#contact").hover(
		function(){//mouseover 
		
				$("#top-contact").fadeIn("slow");
						
					},
					function(){ //mouseout
					
					$("#top-contact").fadeOut("slow");
			
					}
					
					
			
			
			); 

});

