var mask;
var iOS=((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)));

function pageLoaded(){
	// Fool the validator by post adding target='_blank' to links with rel=external
	$('a[rel=external]').attr('target', '_blank');

	// links with rel=popup will open in a popup window
	$('a[rel=popup]').click(function(e){
		e.preventDefault();
		href = $(this).attr('href');
		_popup = window.open(href, "_popup", "width=400,height=400,directories=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0");
		if (window.focus) {_popup.focus()}
	});
	
	
	// Dropdown menus
	$("ul.dropdown li").hover(function(){
    
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    
    });
    
    $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");

	// Fix IE7 z-index bug
	$(function() {
		   var zIndexNumber = 1000;
		   // Put your target element(s) in the selector below!
		   $("#navigation ul li, #navigation ul li ul, #slideshow-wrapper").each(function() {
				   $(this).css('zIndex', zIndexNumber);
				   zIndexNumber -= 1;
		   });
	});
	
	var d=document;
	var cssdisabled = false;
	var testcss = d.createElement('div');
	testcss.style.position = 'absolute';
	d.getElementsByTagName('body')[0].appendChild(testcss);
	if (testcss.currentStyle) var currstyle = testcss.currentStyle['position'];
	else if (window.getComputedStyle) var currstyle = d.defaultView.getComputedStyle(testcss, null).getPropertyValue('position');
	var cssdisabled = (currstyle == 'static') ? true : false;
	d.getElementsByTagName('body')[0].removeChild(testcss);
	
	if (!cssdisabled){
		// Slide Show
		createSlideshow();
		
		// Services Menu
		$('.services-panel').find('.toggle').click(function(e){
			e.preventDefault();
			
			
			if ($(this).parent().hasClass('open-li')){
				$(this).parent().removeClass('open-li');
			} else {
				$(this).parent().addClass('open-li');
			}
		});
		
		// News Feed
		$.ajax({
  			url: "/_api/getLatestNews.php",
	  		success: function(data){
				$('.news-panel').html(data);
				createNewsRoller();
  			}
		});
		
		// Social network tooltips
		$('#social-networking dd').hide();
		
		$('#social-networking dt').mouseover(function(){
			createTooltip($(this).next().html());
		});	
	
		$('#social-networking dt').mouseout(function(){
			killTooltip();
		});	
		
		// Contact page map links
		
		if ($('#contact-page').length>0 && !iOS){
			initMap();
		}
			
		// Team page concertina
		if ($('#team-page').length>0 && !iOS){
			initConcertina();
		}
	
		// Sponsorship page images
		if ($('#about-page').length>0 && !iOS && $('#about-page').hasClass('sponsorship')){
		
			initImages();
		}
		
		if ($('#fees-funding-page').length>0 || $('#contact-page').length>0){
			if (document.activity_indicator==1)	initActivityIndicator();
		}
		
		mask = document.createElement('div');
		mask.setAttribute('id', 'mask');
		$(mask).css('width', '100%');
		$(mask).css('position', 'absolute');
		$(mask).css('background', '#000000');
		$(mask).css('top', '0');
		$(mask).css('opacity', '0.2');
		$(mask).css('height', $('body').outerHeight()); 
		$(mask).css('display', 'none');
		$('body').append(mask);
		document.ondragstart = function(){ return false; }

	}

}

function setHomePage(){
    if (document.all){
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage('http://www.noblesolicitors.co.uk');
    } else if (window.sidebar){
        if(window.netscape){
          try {
			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
          } catch(e){
			alert("Sorry, this action is not available in the browser that you are using.");
		  }
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage','http://www.noblesolicitors.co.uk');
	}
}


function verifyFileTypeSelected(obj){
	path = obj.value;
	ext = path.substr(path.lastIndexOf('.')+1).toLowerCase();
	switch (ext){
		case 'pdf':
		case 'doc':
		case 'docx':
		case 'jpg':
		case 'png':
			break;
		default:
			alert('Invalid file: Files will only be accepted in .pdf, .doc, .docx, .jpg or .png format');
			break;	
	}
}

function checkPayPalForm(f){
	amount = parseInt(f.amount_1.value);
	if (amount <= 0 || amount*1!=amount){		
		alert("Please type the amount you are paying in GBP. Type numbers only (no pound sign).");
		return false;
	}
	if (f.item_name_1.value == ""){
		alert("Please enter the invoice number which you wish to pay.");
		return false;
	}
	
	showActivityIndicator();
	return true;
}

