var popup_settings = {
	closeHTML: "<div class='popup_close'></div>",
	opacity: 50
};

$(document).ready(function() { 

	$("#nav li:last-child").addClass('last');

	$('#nav li').hover(
		function () {
        	$('a:first', this).addClass('hover');
			//$('ul', this).slideDown(50);
			$('ul', this).show();
		}, 
		function () {
        	$('a:first', this).removeClass('hover');
			//$('ul', this).slideDown(50);
			$('ul', this).hide();
		}
	);

	//$("ul.list-news li a").ThreeDots({ max_rows:1, alt_text_t:true });

    $(".pass_it_on").click(function(e) {
        $.modal.close();
        e.preventDefault();
        $(".pass_it_on_popup").modal(popup_settings);
    });

  	if($('#homepagecycle').length > 0) {
	  $('#homepagecycle').cycle({
			fx: 'fade',
			speed: 200,
			timeout: 8000,
			pager: '.switcher',
            activePagerClass: 'active'
		});
	}
    
  	if($('.sectioncycle').length > 0) {
      $('.sectioncycle').each(function(){
          var switcherid = $(this).attr('rel');
          $(this).cycle({
                fx: 'fade',
                speed: 200,
                timeout: 8000,
                pager: '#switcher_'+switcherid,
                activePagerClass: 'active'
          });
      });
      
	}
    
  	if($('.galleryviewer').length > 0) {
	  $('.galleryviewer').cycle({
			fx: 'fade',
			speed: 200,
			timeout: 8000,
			pager: '#switcher-gallery',
            activePagerClass: 'active',
            next: '.link-next',
            prev: '.link-prev'
		});
	}
    
	if($('#carousel').length > 0) {
	  $('#carousel').cycle({
			fx: 'fade',
			speed: 200,
			timeout: 8000,
			pager: '.switcher',
            activePagerClass: 'active'
		});
	}

	if($('#carousel_new').length > 0) {
	  $('#carousel_new').cycle({
			fx: 'fade',
			speed: 200,
			timeout: 8000,
			prev: '#cycle_controls .prev',
			next: '#cycle_controls .next',
            after: carouselLabel
		});
	}
	function carouselLabel(curr,next,opts) {
    	$('#cycle_controls').show();
		var msg = (opts.currSlide + 1) + ' من ' + opts.slideCount;
		$('#cycle_controls .label').html(msg);
	};
    
	$("input.keywords").autocomplete("/custom/_autocompleter/",{
    	cacheLength: 0,
    	minChars: 3,
    	formatItem: function (row) { return row[0] },
    	formatResult: function (row){ return row[1] }
    }).result(function(event, item) {
    	//redirect to the URL in the string
    	window.location.href = "http://ar.mubadala.ae/general/page/"+item[1];
    });	  
    
    $("a.showMore").click(function(e){
    	e.preventDefault();
    	var id = $(this).attr('rel');
        $("#summary_"+id).hide();
        $("#full_"+id).show();
    });
	
    $("a.showLess").click(function(e){
    	e.preventDefault();
    	var id = $(this).attr('rel');
        $("#full_"+id).hide();
        $("#summary_"+id).show();
    });
	
    $(".gallery-asset a[rel^='prettyPhoto'], .intro-video a[rel^='prettyPhoto'], .intro-main a[rel^='prettyPhoto']").prettyPhoto({theme:'dark_rounded',default_width:600,default_height:500});
    
    if($("#map").length > 0) {populateMap();}
    if($("#panelmap").length > 0) {populatePanelMap();}
    if($("#map_park").length > 0) {populateParkMap();}

});  

function populateMap() {
	var map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(24.46358364845318, 54.388439655303955), 12);
	map.setUIToDefault();

	
					var points = new Array(2);
		
		points[1] = [12,12,'<div class="infoContainer"><h2>test</h2><p class="address">123</p></div>'];

	
		
		points[2] = [24.46358364845318,54.388439655303955,'<div class="infoContainer"><h2>Abu Dhabi</h2><p class="address">Abu Dhabi, UAE</p></div>'];

	

	for(var i=1; i < points.length; i++) {
		var point = new GLatLng(points[i][0],points[i][1]);
		var windowInfo = points[i][2];
		var marker = createMarker(point,windowInfo);
		map.addOverlay(marker);
	}
}

function populateParkMap() {
	var map = new GMap2(document.getElementById("map_park"));
	map.setCenter(new GLatLng(24.464309,54.387978), 17);
	map.setUIToDefault();
        var point = new GLatLng(24.464309,54.387978);
        
		var windowInfo = '<p>Mamoura buildings<br />Near Muroor (4th) Road &amp; Mohamed Bin Khalifa (15th) Street<br />Abu Dhabi<br />United Arab Emirates<br />T +971 2 413 0000<br /><br></p>';
        
		var marker = createMarker(point,windowInfo);
		map.addOverlay(marker);
}


function populatePanelMap() {
	var map = new GMap2(document.getElementById("panelmap"));
	map.setCenter(new GLatLng(25.2447, 55.2832), 5);
	map.setUIToDefault();
}


function createMarker(point, overlayText) {
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(overlayText);});
	return marker;
}

/*
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {oldonload();}
			func();
		}
	}
}
if($("#map").length > 0) {addLoadEvent(populateMap);}
*/



function hideFormText() {
	var _inputs = document.getElementsByTagName('input');
	var _txt = document.getElementsByTagName('textarea');
	var _value = [];
	
	if (_inputs) {
		for(var i=0; i<_inputs.length; i++) {
			if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {
				
				_inputs[i].index = i;
				_value[i] = _inputs[i].value;
				
				_inputs[i].onfocus = function(){
					if (this.value == _value[this.index])
						this.value = '';
				}
				_inputs[i].onblur = function(){
					if (this.value == '')
						this.value = _value[this.index];
				}
			}
		}
	}
	if (_txt) {
		for(var i=0; i<_txt.length; i++) {
			_txt[i].index = i;
			_value['txt'+i] = _txt[i].value;
			
			_txt[i].onfocus = function(){
				if (this.value == _value['txt'+this.index])
					this.value = '';
			}
			_txt[i].onblur = function(){
				if (this.value == '')
					this.value = _value['txt'+this.index];
			}
		}
	}
}

if (window.addEventListener){
	window.addEventListener("load", hideFormText, false);
}
else if (window.attachEvent){
	window.attachEvent("onload", hideFormText);
}


 

