if(typeof($) != 'undefined')
{
    //setup vars go here
    
    $(document).ready(function(){
        
        //don't put code in here, call functions!
        setupExternals();
        caseStudySlider();
        officesGMap();
        roOfficesGMap();
        plOfficesGMap();
        ukOfficesGMap();
        //qaOfficesGMap();
        homeFeaturesSlider();
    }); 
    
    function homeFeaturesSlider()
    {
        if($('.slideshowContainer').length != 0)
        {
	        $('.homeSlideshowNav').show();
	        
            $('.slideshowContainer').cycle({ 
                fx:     'fade', //use the fade effect
                speed:  1000, //transition in 1 sec
                timeout: 6000, //transition after 6 secs - 0 to not auto start
                slideExpr: '.slide', //only use images with a class bannerBackground for the slideshow
                pager: '.homeSlideshowNav', //use this element to contain the page links
                cleartype: 0,
                pagerEvent: 'click',
                pauseOnPagerHover: false,
                pagerAnchorBuilder: function (idx, slide) {
                    return '<li class="slideNavBullet"><a>'+ idx +'</a></li>';
                }
            });
        }
	}
    
    function qaOfficesGMap()
    {
	    if($('#qaOfficeMap').length > 0)
	    {
			var map = new GMap2(document.getElementById("qaOfficeMap"));
			
			map.setCenter(new GLatLng(25.27667669995565, 51.52244567871094), 16);
			map.setUIToDefault();
			
			var blueIcon = new GIcon(G_DEFAULT_ICON);
        	blueIcon.image = "/images/office-marker.png";
        	blueIcon.shadow = "";
        	blueIcon.iconSize = new GSize(48, 48);
        	blueIcon.iconAnchor = new GPoint(16, 48);
        	blueIcon.infoWindowAnchor = new GPoint(16, 48);
        	blueIcon.imageMap=[0,0, 47,0, 47,47, 0,47]; //imagemap style polygon coords, making a square from top/left to top/right to bottom/right to bottom/left

        	markerOptions = { icon:blueIcon };
			
        	var qaMarker = new GMarker(new GLatLng(25.27667669995565, 51.52244567871094), markerOptions);
        	/*GEvent.addListener(roMarker, "click", function() { roMarker.openInfoWindowHtml("<h2>PJ Media Romania Office</h2><br />Address here"); });*/
        	map.addOverlay(qaMarker);
	    }
    }
    
    function ukOfficesGMap()
    {
	    if($('#ukOfficeMap').length > 0)
	    {
			var map = new GMap2(document.getElementById("ukOfficeMap"));
			
			map.setCenter(new GLatLng(51.572868782073606, -0.7607345943450928), 14);
			map.setUIToDefault();
			
			var blueIcon = new GIcon(G_DEFAULT_ICON);
        	blueIcon.image = "/images/office-marker.png";
        	blueIcon.shadow = "";
        	blueIcon.iconSize = new GSize(48, 48);
        	blueIcon.iconAnchor = new GPoint(16, 48);
        	blueIcon.infoWindowAnchor = new GPoint(16, 48);
        	blueIcon.imageMap=[0,0, 47,0, 47,47, 0,47]; //imagemap style polygon coords, making a square from top/left to top/right to bottom/right to bottom/left

        	markerOptions = { icon:blueIcon };
			
        	var ukMarker = new GMarker(new GLatLng(51.572868782073606, -0.7607345943450928), markerOptions);
        	/*GEvent.addListener(roMarker, "click", function() { roMarker.openInfoWindowHtml("<h2>PJ Media Romania Office</h2><br />Address here"); });*/
        	map.addOverlay(ukMarker);
	    }
    }
    
    function plOfficesGMap()
    {
	    if($('#plOfficeMap').length > 0)
	    {
			var map = new GMap2(document.getElementById("plOfficeMap"));
			
			map.setCenter(new GLatLng(52.10440305754613, 20.621895790100098), 16);
			map.setUIToDefault();
			
			var blueIcon = new GIcon(G_DEFAULT_ICON);
        	blueIcon.image = "/images/office-marker.png";
        	blueIcon.shadow = "";
        	blueIcon.iconSize = new GSize(48, 48);
        	blueIcon.iconAnchor = new GPoint(16, 48);
        	blueIcon.infoWindowAnchor = new GPoint(16, 48);
        	blueIcon.imageMap=[0,0, 47,0, 47,47, 0,47]; //imagemap style polygon coords, making a square from top/left to top/right to bottom/right to bottom/left

        	markerOptions = { icon:blueIcon };
			
        	var plMarker = new GMarker(new GLatLng(52.10440305754613, 20.621895790100098), markerOptions);
        	/*GEvent.addListener(roMarker, "click", function() { roMarker.openInfoWindowHtml("<h2>PJ Media Romania Office</h2><br />Address here"); });*/
        	map.addOverlay(plMarker);
	    }
    }
    
    function roOfficesGMap()
    {
	    if($('#roOfficeMap').length > 0)
	    {
			var map = new GMap2(document.getElementById("roOfficeMap"));
			
			map.setCenter(new GLatLng(44.451037605072244, 26.11404597759247), 16);
			map.setUIToDefault();
			
			var blueIcon = new GIcon(G_DEFAULT_ICON);
        	blueIcon.image = "/images/office-marker.png";
        	blueIcon.shadow = "";
        	blueIcon.iconSize = new GSize(48, 48);
        	blueIcon.iconAnchor = new GPoint(16, 48);
        	blueIcon.infoWindowAnchor = new GPoint(16, 48);
        	blueIcon.imageMap=[0,0, 47,0, 47,47, 0,47]; //imagemap style polygon coords, making a square from top/left to top/right to bottom/right to bottom/left

        	markerOptions = { icon:blueIcon };
			
        	var roMarker = new GMarker(new GLatLng(44.451037605072244, 26.11404597759247), markerOptions);
        	/*GEvent.addListener(roMarker, "click", function() { roMarker.openInfoWindowHtml("<h2>PJ Media Romania Office</h2><br />Address here"); });*/
        	map.addOverlay(roMarker);
	    }
    }
    
    function officesGMap()
    {
	    if($('#allOfficesMap').length > 0)
	    {
			var map = new GMap2(document.getElementById("allOfficesMap"));
			
			map.setCenter(new GLatLng(42, 25), 3);
			map.setUIToDefault();
			
			var blueIcon = new GIcon(G_DEFAULT_ICON);
        	blueIcon.image = "/images/office-marker.png";
        	blueIcon.shadow = "";
        	blueIcon.iconSize = new GSize(48, 48);
        	blueIcon.iconAnchor = new GPoint(16, 48);
        	blueIcon.infoWindowAnchor = new GPoint(16, 48);
        	blueIcon.imageMap=[0,0, 47,0, 47,47, 0,47]; //imagemap style polygon coords, making a square from top/left to top/right to bottom/right to bottom/left

        	markerOptions = { icon:blueIcon };
        	
        	var ukMarker = new GMarker(new GLatLng(51.572868782073606, -0.7607345943450928), markerOptions);
        	GEvent.addListener(ukMarker, "click", function() { window.location = "/contact/uk.cfm" });
        	/*GEvent.addListener(ukMarker, "click", function() { map.setCenter(new GLatLng(51.572868782073606, -0.7607345943450928), 14); });*/
        	/*GEvent.addListener(ukMarker, "click", function() { ukMarker.openInfoWindowHtml("<h2>PJ Media UK Head Office</h2><p>Network House,<br />Marlow,<br />SL7 1EY</p>"); });*/
			map.addOverlay(ukMarker);
			
        	var roMarker = new GMarker(new GLatLng(44.451037605072244, 26.11404597759247), markerOptions);
        	GEvent.addListener(roMarker, "click", function() { window.location = "/contact/romania.cfm" });
        	/*GEvent.addListener(roMarker, "click", function() { roMarker.openInfoWindowHtml("<h2>PJ Media Romania Office</h2><br />Address here"); });*/
        	map.addOverlay(roMarker);
        	
        	var plMarker = new GMarker(new GLatLng(52.10440305754613, 20.621895790100098), markerOptions);
        	GEvent.addListener(plMarker, "click", function() { window.location = "/contact/poland.cfm" });
        	/*GEvent.addListener(plMarker, "click", function() { plMarker.openInfoWindowHtml("<h2>PJ Media Poland Office</h2><br />Address here"); });*/
        	map.addOverlay(plMarker);
        	
        	/*var qaMarker = new GMarker(new GLatLng(25.27667669995565, 51.52244567871094), markerOptions);
        	GEvent.addListener(qaMarker, "click", function() { window.location = "/contact/qatar.cfm" });
        	GEvent.addListener(qaMarker, "click", function() { qaMarker.openInfoWindowHtml("<h2>PJ Media Qatar Office</h2><br />Address here"); });
        	map.addOverlay(qaMarker); */ 	
	    }
    }

    function setupExternals()
    {
        $('a.external').attr('target','_blank');
    }
    
    function caseStudySlider()
    {
        if($('.caseStudySlider').length != 0)
        {
	        $('.caseStudySliderNav').show();
	        
            $('.caseStudySlider').cycle({ 
                fx:     'fade', //use the fade effect
                speed:  1000, //transition in 1 sec
                timeout: 6000, //transition after 6 secs - 0 to not auto start
                slideExpr: '.caseStudyPane', //only use images with a class bannerBackground for the slideshow
                pager: '.caseStudySliderNav', //use this element to contain the page links
                cleartype: 0,
                pagerEvent: 'click',
                pauseOnPagerHover: false,
                pagerAnchorBuilder: function (idx, slide) {
                    return '<li><a>' + (idx+1) + '</a></li>';
                }
            });

        }
	}
}