$(document).ready(function(){
  
  $('a').filter("[href*=http://]").not('[href*=stir.ac]').click(function(){window.open(this.href);return false;}).attr('title','link opens in a new window');
  
  $('.square').css({display: "none",position: "absolute",top: "40%",left: "200px"});
  $('#jquerytabs').tabs({remote:false, fxSlide: false, fxFade: false, fxSpeed: 'fast'});
  
  $('#jquerytabs .tabs-container a').each(function(){ $(this).append(linkIconAppend(this));});

  $('#walkingRoutes').jqDrag().jqm({overlay:50, trigger:'#walkingRoutesShow', toTop:true});
  $('#campusRoutes').jqDrag().jqm({overlay:50, trigger:'#campusRoutesShow', toTop:true});
  $('#cyclingRoutes').jqDrag().jqm({overlay:50, trigger:'#cyclingRoutesShow', toTop:true});
  $('#newCyclists').jqDrag().jqm({overlay:50, trigger:'#newCyclistsShow', toTop:true});
  $('#cycleParking').jqDrag().jqm({overlay:50, trigger:'#cycleParkingShow', toTop:true});
  $('#staffStudentParking').jqDrag().jqm({overlay:50, trigger:'#staffStudentParkingShow', toTop:true});
  $('#useTheBusInStirling').jqDrag().jqm({overlay:50, trigger:'#useTheBusInStirlingShow', toTop:true});
  $('#stationBusStopMap').jqDrag().jqm({overlay:50, trigger:'#stationBusStopMapShow', toTop:true});


  $('.printme').click(function(){
    alert(this.href);
	window.open(this.href,'printwin');
	alert(printwin);
	printwin.window.print();
	return false;
  });
  
});


function linkIconAppend(l){
	if (l.href.indexOf('mailto') > -1){
		return '&nbsp;<img src="http://www.external.stir.ac.uk/img/icons/email.gif" align="texttop">';
	}
	
	if ((l.href.indexOf('http:') > -1) || (l.href.indexOf('https:') > -1)){
		if (l.href.indexOf('stir.ac.uk') == -1){
			//external link
			return '&nbsp;<img src="http://www.external.stir.ac.uk/img/icons/new-window.gif" alt="arrow" title="link opens in a new window" align="texttop">';
		}
	}
	
	if (l.id.indexOf('Show') > -1){
		return '&nbsp;<img src="http://www.externalrelations.stir.ac.uk/img/template-graphics/popup-icon.gif" alt="Pop-up" title="this link will open a box within this window" border="0" />';
	}
}

function clickHereToPrint(id)
{ 
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
      disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
  var content_vlue = document.getElementById(id).innerHTML; 
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>University of Stirling - Getting Here - Print Out</title>'); 
   docprint.document.write('</head><body onLoad="self.print()">');          
   docprint.document.write(content_vlue);          
   docprint.document.write('</body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
}