

/* ------------------------------------------------ JQUERY COOKIES FUNCTION ------------------------------------------------ */

jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options=$.extend({},options);options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};

/* ------------------------------------------------ JQUERY COOKIES FUNCTION ------------------------------------------------ */

function xtractFile(data){
var m = data.match(/(.*)\/([^\/\\]+)(\.\w+)$/);
if(m == null) { m = "null"; }
return {path: m[1], file: m[2], extension: m[3]}
}

function initGmap() {    
	var latlng = new google.maps.LatLng(53.848572, -7.062184);    
	var myOptions = {      zoom: 13,      
						   center: latlng,      
						   mapTypeId: google.maps.MapTypeId.ROADMAP 
					};    
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	var contentString = 'Kelly Bros - RoadLines,<br />  Baileborough Road, <br />Virginia, Co. Cavan,<br /> Ireland.';
	//create info window
	var infowindow = new google.maps.InfoWindow({    
		content: contentString,
        maxWidth: 100
	});
	
	var marker = new google.maps.Marker({      
		position: latlng,      
		map: map     
		//title:"Hello World!"  //this shows up as a tooltip
	});
	
	google.maps.event.addListener(marker, 'click', function() {  
		infowindow.open(map,marker);
	});
}


jQuery(document).ready(function() 
{

	if(typeof sIFR == "function"){
	
		// This is the preferred "named argument" syntax
		sIFR.replaceElement( named(
	   {
		   sSelector:".homePanel h1 span", sFlashSrc:"/flash/universal_condensed.swf", 
		   sColor:"#333333", sCase:"upper", sWmode:"transparent"
		}));
		sIFR.replaceElement( named(
	   {
		   sSelector:".callToAction h3 span", sFlashSrc:"/flash/universal_condensed.swf", 
		   sColor:"#333333", sCase:"upper", sWmode:"transparent"
		}));
		sIFR.replaceElement( named(
	   {
		   sSelector:".homePanel h3 span", sFlashSrc:"/flash/universal_condensed.swf", 
		   sColor:"#333333", sCase:"upper", sWmode:"transparent"
		}));
		sIFR.replaceElement( named(
	   {
		   sSelector:".sidepanel h2 span", sFlashSrc:"/flash/universal_condensed.swf", 
		   sColor:"#333333", sCase:"upper", sWmode:"transparent"
		}));
	};

	/* ------------------------------------------------ FONT SIZE TOGGLE ------------------------------------------------ */
	// If there's a cookie present for this site, assign the font size based on this value.
	if($.cookie('fontSizeCookie'))
	{
		var getCookie = parseFloat($.cookie('fontSizeCookie'));
		jQuery("#mainWrapper").css({ 'font-size' : getCookie+'em' });
	}
	
	// Increase the font size based on <current cookie size> + 0.25.
	jQuery("a.font_inc").click(function() 
	{
		if($.cookie('fontSizeCookie'))
		{
			
			$.cookie('fontSizeCookie', parseFloat($.cookie('fontSizeCookie'))+0.25, { path: '/' });
			jQuery("#mainWrapper").css({ 'font-size' : parseFloat($.cookie('fontSizeCookie'))+'em' });
		}
		else // No Cookie Present? Set a Cookie based on initial step-up (0.25), then increase font size
		{
			$.cookie('fontSizeCookie', 1.25, { path: '/' });
			jQuery("#mainWrapper").css({ 'font-size' : parseFloat($.cookie('fontSizeCookie'))+'em' });
		}
	});
	
	// Decrease the font size based on <current cookie size> - 0.25.
	jQuery("a.font_dec").click(function() 
	{
		if($.cookie('fontSizeCookie'))
		{
			if(parseFloat($.cookie('fontSizeCookie')) > 1.0)
			{
				$.cookie('fontSizeCookie', parseFloat($.cookie('fontSizeCookie'))-0.25, { path: '/' });
				jQuery("#mainWrapper").css({ 'font-size' : parseFloat($.cookie('fontSizeCookie'))+'em' });
			}
		}
	});
	/* ------------------------------------------------ FONT SIZE TOGGLE ------------------------------------------------ */

	jQuery(function() {
		jQuery(".carousel").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			visible: 2,
			auto: 3000,
			speed: 400
		});
	});
	
	// Jquery Lightbox
	jQuery(function() { jQuery('.gallery_container .gallery_item a').lightBox(); });

	// Utilities Tooltips
	jQuery(".utilities li").hover(
		function() 
		{ jQuery(this).children("p").fadeIn("fast"); },
		function() 
		{ jQuery(this).children("p").fadeOut("fast"); }
	);
	
	// Assign Zebra Cols to subnav links
	i = 0;
	jQuery("#subnav ul li").each( function(i){
		i % 2 == 0 ? jQuery(this).addClass("zebra_row_0") : jQuery(this).addClass("zebra_row_1");
		i++;
	});

	// Jquery Lightbox
	$(function() { $('.galleryLightbox li a, .cmaImgs a').lightBox(); });

	 // highlight the current side-bar subnav link.
    if (document.getElementById("subnav")) {
        var sublinks = document.getElementById("subnav").getElementsByTagName("a");
        for (var i = 0; i < sublinks.length; i++)
        { if (sublinks[i].href == document.location.href) { sublinks[i].parentNode.className += " currentPage"; } }
    }
	
	/* animated the sub menu
	jQuery("#subnav ul li a").hover(
		function(){ jQuery(this).parent("li").animate({ marginRight: "0px"}, 200 ); },								
		function(){ jQuery(this).parent("li").animate({ marginRight: "15px"}, 200 ); }	
	);*/
	
	/* Google map functionality */
	if($("#map_canvas").length > 0) {
		initGmap();
	}
	
	if(document.getElementById("homeFlash"))
	{
		var so = new SWFObject("/flash/homepage_003.swf", "flash_area", "950", "350", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/homepage_003.xml");
		so.write("homeFlash");  
	}
	
	if(document.getElementById("aboutUs_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_aboutUs.xml");
		so.write("aboutUs_flash");  
	}
	
	if(document.getElementById("services_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_services.xml");
		so.write("services_flash");  
	}

	if(document.getElementById("application_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_application.xml");
		so.write("application_flash");  
	}

	if(document.getElementById("manufacturing_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_manufacturing.xml");
		so.write("manufacturing_flash");  
	}

	if(document.getElementById("products_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_products.xml");
		so.write("products_flash");  
	}

	if(document.getElementById("utilities_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_utilities.xml");
		so.write("utilities_flash");  
	}

	if(document.getElementById("anti-skid_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_anti-skid.xml");
		so.write("anti-skid_flash");  
	}

	if(document.getElementById("colouredSurfacing_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_colouredSurfacing.xml");
		so.write("colouredSurfacing_flash");  
	}

	if(document.getElementById("extrusion_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_extrusion.xml");
		so.write("extrusion_flash");  
	}

	if(document.getElementById("removal_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_removal.xml");
		so.write("removal_flash");  
	}

	if(document.getElementById("spray_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_spray.xml");
		so.write("spray_flash");  
	}

	if(document.getElementById("airAndRail_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_airAndRail.xml");
		so.write("airAndRail_flash");  
	}
	
	if(document.getElementById("carPark_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_carPark.xml");
		so.write("carPark_flash");  
	}

	if(document.getElementById("gameCourts_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_gameCourts.xml");
		so.write("gameCourts_flash");  
	}

	if(document.getElementById("roadMarking_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_roadMarking.xml");
		so.write("roadMarking_flash");  
	}
	
		if(document.getElementById("internalLineMarking_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_internalLineMarking.xml");
		so.write("internalLineMarking_flash");  
	}

		if(document.getElementById("screed_flash"))
	{
		var so = new SWFObject("/flash/subLoader.swf", "flash_area", "950", "220", "8", "#ffffff");
		so.addVariable("parseFileName", "/flash/subpage_screed.xml");
		so.write("screed_flash");  
	}

	// put classes on links to file types
	if(document.getElementById("maincontent"))
	{
		var dls = document.getElementById("maincontent").getElementsByTagName("a");
		var link_class = "dlicon ";
		for(var x = 0; x < dls.length; x++)
		{
			var parsedObject = xtractFile(dls[x].href);
			if(parsedObject.extension) { dls[x].className = dls[x].className + " " + link_class + parsedObject.extension.substring(1, parsedObject.extension.length).toLowerCase(); }
		} // end for
	}// end if(getElement)


}); // END jQuery(document).ready

