var leftv, topfloatbox, topcontent;

function csb(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; csb(navigator.userAgent);

(function(a){a.fn.easySlider=function(b){var c={prevId:"prevBtn",prevText:"Previous",nextId:"nextBtn",nextText:"Next",controlsShow:true,controlsBefore:"",controlsAfter:"",controlsFade:true,firstId:"firstBtn",firstText:"First",firstShow:false,lastId:"lastBtn",lastText:"Last",lastShow:false,vertical:false,speed:600,auto:false,pause:7000,continuous:false,numeric:false,numericId:"controls"};var b=a.extend(c,b);this.each(function(){function n(d,j){if(g){g=false;var k=i;switch(d){case"next":i=k>=h?b.continuous?i+1:h:i+1;break;case"prev":i=i<=0?b.continuous?i-1:0:i-1;break;case"first":i=0;break;case"last":i=h;break;default:i=d;break}var l=Math.abs(k-i);var q=l*b.speed;if(!b.vertical){p=i*e*-1;a("ul",c).animate({marginLeft:p},{queue:false,duration:q,complete:m})}else{p=i*f*-1;a("ul",c).animate({marginTop:p},{queue:false,duration:q,complete:m})}if(!b.continuous&&b.controlsFade){if(i==h){a("a","#"+b.nextId).hide();a("a","#"+b.lastId).hide()}else{a("a","#"+b.nextId).show();a("a","#"+b.lastId).show()}if(i==0){a("a","#"+b.prevId).hide();a("a","#"+b.firstId).hide()}else{a("a","#"+b.prevId).show();a("a","#"+b.firstId).show()}}if(j)clearTimeout(o);if(b.auto&&d=="next"||d=="prev"){o=setTimeout(function(){n("next",false)},l*b.speed+b.pause)}}}function m(){if(i>h)i=0;if(i<0)i=h;if(!b.vertical){a("ul",c).css("margin-left",i*e*-1)}else{a("ul",c).css("margin-left",i*f*-1)}g=true;if(b.numeric)l(i)}function l(c){c=parseInt(c)+1;a("li","#"+b.numericId).removeClass("current");a("li#"+b.numericId+c).addClass("current")}var c=a(this);var d=a("li",c).length;var e=a("li",c).width();var f=a("li",c).height();var g=true;c.width(e);c.height(f);c.css("overflow","hidden");var h=d-1;var i=0;a("ul",c).css("width",d*e);if(b.continuous){a("ul",c).prepend(a("ul li:last-child",c).clone().css("margin-left","-"+e+"px"));a("ul",c).append(a("ul li:nth-child(2)",c).clone());a("ul",c).css("width",(d+1)*e)}if(!b.vertical)a("li",c).css("float","left");if(b.controlsShow){var j=b.controlsBefore;if(b.numeric){j+='<ol id="'+b.numericId+'"></ol>'}else{if(b.firstShow)j+='<span id="'+b.firstId+'"><a href="javascript:void(0);">'+b.firstText+"</a></span>";j+=' <span id="'+b.prevId+'"><a href="javascript:void(0);">'+b.prevText+"</a></span>";j+=' <span id="'+b.nextId+'"><a href="javascript:void(0);">'+b.nextText+"</a></span>";if(b.lastShow)j+=' <span id="'+b.lastId+'"><a href="javascript:void(0);">'+b.lastText+"</a></span>"}j+=b.controlsAfter;a(c).after(j)}if(b.numeric){for(var k=0;k<d;k++){a(document.createElement("li")).attr("id",b.numericId+(k+1)).html("<a rel="+k+' href="javascript:void(0);">'+(k+1)+"</a>").appendTo(a("#"+b.numericId)).click(function(){n(a("a",a(this)).attr("rel"),true)})}}else{a("a","#"+b.nextId).click(function(){n("next",true)});a("a","#"+b.prevId).click(function(){n("prev",true)});a("a","#"+b.firstId).click(function(){n("first",true)});a("a","#"+b.lastId).click(function(){n("last",true)})}var o;if(b.auto){o=setTimeout(function(){n("next",false)},b.pause)}if(b.numeric)l(0);if(!b.continuous&&b.controlsFade){a("a","#"+b.prevId).hide();a("a","#"+b.firstId).hide()}})}})(jQuery)


$(document).ready(function(){
	
	 $('.btnPrint').click(function(){
		window.print();
	 })
	 
	//News Scroll 
     if($('ul#circleFacts').html()!=null){
		licount = $('ul#circleFacts li').size();
		liwidth = parseInt($('ul#circleFacts li').width());
		
		maxLeft = liwidth * licount;
		$('ul#circleFacts').append(  "<li>" + $('ul#circleFacts li:first').html() + "</li>" );
                var calcWidth = parseInt(maxLeft) + parseInt(liwidth) + 10
                console.log(calcWidth)
		$('ul#circleFacts').css('width',(parseInt(maxLeft)+parseInt(liwidth))+'px');
		Cufon.refresh();
	 }			
	 autoslideinterval = setInterval(function(){
		 if($('ul#circleFacts').html()!=null){
			 var gleft = $('ul#circleFacts').css('marginLeft');

		gleft = gleft.replace('px','');
		gleft = gleft - (liwidth) - 26
		
		if((gleft)>(-(maxLeft)))
			$('ul#circleFacts').stop().animate({marginLeft: gleft+'px'});
		else
			$('ul#circleFacts').stop().animate({marginLeft: gleft+'px'}, function(){
					$('ul#circleFacts').css({marginLeft: '0px'});
			});

		 }
		
	 }, 8000);
	 
	//approved Menu 
	$(".sandwiches").hover(function() {
 			  $(this).find('.hoverDiv').stop(true, true).fadeIn("fast");
			  $(".sandwiches").css("z-index","9999");
  			  $(this).css("z-index","100001");
 			}, function() {
 			  $(this).find('.hoverDiv').stop(true, true).fadeOut("fast");
 	});	
	
	
	//Slider Carousel
	$("#slider").easySlider({
		auto: true, 
		continuous: true
	});
	
	//Fresh Facts Fade
	var j = 0;
     var delay = 8000; //millisecond delay between cycles
     function cycleThru(){
             var jmax = $("ul#fadeFacts li").length -1;
             $("ul#fadeFacts li:eq(" + j + ")")
                     .animate({"opacity" : "1"} ,400)
                     .animate({"opacity" : "1"}, delay)
                     .animate({"opacity" : "0"}, 400, function(){
                             (j == jmax) ? j=0 : j++;
                             cycleThru();
                     });
             };

     cycleThru();

if($('#floating-box').html()!=null){
	$("#contentRight").addClass('left592');
	leftv = parseInt($('#main-content').offset().left);
	topfloatbox = parseInt($('#floating-box').offset().top) - 10;
	topcontent = parseInt($('#contentRight').offset().top) + parseInt(15);
}

$(window).scroll(function (e) { 
		floatingfunc('n');
    });

 $(window).mousemove(function(e){
			floatingfunc('m');
        });



//PoP UP
 
 
 $('.sendEmail').click(function(){
	$('.popEmail').css({'top': 0, 'left': 0 });
	$(".formOverlay").css({'opacity': 0.5});;
	$('#msg').hide();
	$('#frm').show();
	document.stf.reset();
 			$('.popEmail').position({ my: 'center', at: 'center', of: window, offset: "0 " });
			var gettop = $('.popEmail').css('top').replace('px','');
			if (gettop<=0)
				$('.popEmail').css({'top': '25%'});
			$(".formOverlay").fadeIn();
			$(".popEmail").fadeIn();
		

	})

	$(window).resize(function(){
		$('.popEmail').css({'top': 0, 'left': 0 });
 		$('.popEmail').position({ my: 'center', at: 'center', of: window, offset: "0 " });		
		
		// Floating
		if($('#floating-box').html()!=null){
			var leftv = parseInt($('#main-content').offset().left);
			var top = parseInt($('#floating-box').offset().top) - 10;
			var topcontent = parseInt($('#contentRight').offset().top) + parseInt(15);
		}
		floatingfunc('n');

	});
	
  $('.closeemail,.formOverlay,.closebtn').click(function(){
			$(".popEmail").fadeOut();
			$(".formOverlay").fadeOut();
	});
	
 if($('#qf0').html()!=null){
		document.qf0.reset();
		document.qf1.reset();
		document.qf2.reset();
		document.qf3.reset();
		document.qf4.reset();
		 }

$('input[type="image"]').hover(function(){
			$(this).css({'opacity': '0.9'});
 	}, function(){
			$(this).css({'opacity': '1.0'})
	});

});//END OF READY


function checkstfvalidate(getform){
		checkedvalidate = true;
		var emailFilter = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,6}$/;
		var getemail = getform.toEmail.value;
		var getemailfrom = getform.fromEAddress.value;


		  if (getform.toEmail.value=="" ||  !(emailFilter.test(getemail)) )
			{
				  $('#toEmail').prev().css('color','#CC0000');
				  checkedvalidate = false;
			}
		  else{
				  $('#toEmail').prev().css('color','#000000');
		  }

		  if (getform.fromEAddress.value=="" ||  !(emailFilter.test(getemailfrom)) )
			{
				  $('#fromEAddress').prev().css('color','#CC0000');
				  checkedvalidate = false;
			}
		  else{
				  $('#fromEAddress').prev().css('color','#000000');
		  }



		  if (getform.name.value=="" )
			{
				  $('#name').prev().css('color','#CC0000');
				  checkedvalidate = false;
			}
		  else{
				  $('#name').prev().css('color','#000000');
		  }


		  if (getform.fromName.value=="" )
			{
				  $('#fromName').prev().css('color','#CC0000');
				  checkedvalidate = false;
			}
		  else{
				  $('#fromName').prev().css('color','#000000');
		  }



	if(checkedvalidate){
 	    $.post('/etnt/emailer.php', $("#emailform").serialize(),function(data){
 				$('#frm').fadeOut();
				$('#msg').fadeIn();
				
			//$('#frm').fadeOut('fast',function(){
//							$('#msg').fadeIn();
//						});
			});
		}

	return false;

}


function floatingfunc(whichevent){
	leftv = parseInt($('#main-content').offset().left)+1;

		if($(window).scrollTop()>= topfloatbox){
			$("#floating-box").css({'position':'fixed', 'top':'10px','left':leftv+'px'})
			}
		else{
			$("#floating-box").css({'position':'absolute', 'top':'368px','left':'0px'})
			}


			perc = 0.70;
			windowTop = $(window).scrollTop();
			newCord = parseFloat(windowTop) * perc;
			var maxtop = (259 + parseInt($("#contentLeft").height())) - $("#contentRight").height();
			var extramin = $("#contentRight").height()-$(window).height();
			var maxScrolltop = ($(document).height() - $(window).height()-120-extramin);

			if( (($(window).scrollTop() < maxScrolltop) ||  (($(window).height()-120) > $("#contentRight").height())) && $(window).scrollTop()> topcontent ){
					if($("#contentRight").hasClass('left592')==true){
						$("#contentRight").removeClass('left592');
					}
					$("#contentRight").css({'position':'fixed', 'left':(parseInt(601)+parseInt(leftv))+'px', 'top':'-5px'})
					$(".mac.chrome #contentRight").css({'position':'fixed', 'left':(parseInt(601)+parseInt(leftv))+'px', 'top':'-5px'})
					$(".mac.gecko #contentRight").css({'position':'fixed', 'left':(parseInt(601)+parseInt(leftv))+'px', 'top':'-5px'})
					$(".ie #contentRight").css({'position':'fixed', 'left':(parseInt(601)+parseInt(leftv))+'px', 'top':'-5px'})

					
			}
			else if($(window).scrollTop()<= topcontent){
				//TOP
						if($("#contentRight").hasClass('left592')==false){
							$("#contentRight").addClass('left592');
						}
						$("#contentRight").css({"top":  "259px"  });
			}
			else {
				//FOOTER

						if($("#contentRight").hasClass('left592')==false){
							$("#contentRight").addClass('left592');
						}
						$("#contentRight").css({ "top":  maxtop+"px" });
			}
}



function changeQuotation()
{
	if($("#contentRight").css('left')=='623px'){
		$(".ie7 #contentRight").css({'left':'592px','margin-left':'0px'});
		$("#contentRight").css({'*left':'592px','margin-left':'0px'}); 
		clearInterval(intervalQ1);
	}
}
