	/* Scgmtimes top navigation and others*/
	
	$(document).ready(function(){
	
		// tooltips
			wtooltip();
			
		// Navigation menus
			var timeout    = 500;
			var closetimer = 0;
			var ddmenuitem = 0;

			function navmenu_open()
			{  navmenu_canceltimer();
			   navmenu_close();
			   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

			function navmenu_close()
			{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

			function navmenu_timer()
			{  closetimer = window.setTimeout(navmenu_close, timeout);}

			function navmenu_canceltimer()
			{  if(closetimer)
			   {  window.clearTimeout(closetimer);
				  closetimer = null;}}

			$(document).ready(function()
			{  $('#navmenu > li').bind('mouseover', navmenu_open)
			   $('#navmenu > li').bind('mouseout',  navmenu_timer)});

			document.onclick = navmenu_close;
		// end menu
		
		// Just scroll to top
			function scrollToTop () {
				$('html, body').animate({scrollTop:0}, 'slow');
				return false;
			}
		
		/* wayfarer tool tip */
			function wtooltip() {
			//$(function() {
				$("a, input, img").wTooltip({
					offsetX: -150,
					style: { 
						border: "1px solid #d1caad", 
						background: "#fbfbf0",
						color: "#333", 
						padding: "10px", 
						zIndex: "1000", 
						textAlign: "left",
						fontSize: "15px",
						maxWidth: "300px",
						lineHeight: "1.5"
					},
					degrade: false	
				});
			} // end tool tip
			
			
		/* PAGE SPECIFIC  */
		
			if (pageid == 'article') {
				$("#articlesDiv").resizable({ 
						minWidth: 320, 
						maxWidth: 870,
						handles: 'e',
						resize: function (event, ui) {
							$("#articlesDiv").height('auto');
							fadeTOC();
						}					
					});
			} else if (pageid == 'audio' || pageid == 'video') {		
					$("#audiosDiv").resizable({ 
						minWidth: 340, 
						maxWidth: 870,
						handles: 'e',
						resize: function (event, ui) {
							$("#audiosDiv").height('auto');						
						} ,					
						stop: function (event, ui) {
							$("#col2").height($("#col1").height());
								if (pageid == 'audio') {
									$('#audioDiv').stickyfloat({ duration: 400, startOffset: 286, offsetY: 286 });
								}
						}
					});	
			} else if (pageid == 'books') {
				$("#popdialog").dialog( { 
					autoOpen: false,					
					width: 360,
					hide: 'slide'
				});
			
			} else if (pageid == 'home') {
				$("#popdialog").dialog( { 
					autoOpen: false,					
					width: 360,
					show: 'slide',
					hide: 'slide'
				});	
	
				/*$('#slideshow').gwSlideshow({    
					delay            : 2000,    // 2 seconds visibility before transition    
					transition       : 'fade', // Valid types: fade or slide    
					transition_speed : 1000,    // How fast transition itself takes place    
					border           : '1px solid #fbfbf0',    
					bg_color         : '#fbfbf0',    
					height           : '160px',    
					width            : '220px'
				});*/
			} else if (pageid == 'album') {				
				$('#slideshowDiv').cycle({
					fx:    'fade', 
					delay: -4000
				});
			}
	
		/********************************************************************/
		/* click Behaviours */
			bindBehaviours();
			function bindBehaviours () {				
				$("a").die();
				$("a").live('click', function(event) {
					if ($(event.target).is("#articleViewLink") ) {						
						event.preventDefault();
						minimizeArticleTOC();						
						getArticle($(this).attr("documentid"));
						return false;
					} else if ($(event.target).is("#audioPlayLink") ) {
						event.preventDefault();
						minimizeAudioTOC();
						return false;
					} else if ($(event.target).is("#top")) {
						scrollToTop();
						return false;
					} else if ($(event.target).is("#scgmpop")) {
						var item = $(this).attr("item");
						var url = "scgmbookspop.php?id=" + item;
						$("#popdialog").load(url).dialog('open');
						return false;
					} else if ($(event.target).is("#scgmquery")) {						
						var url = "scgmquery.php";						
						$("#popdialog").load(url).dialog('open');
						return false;
					} else if ($(event.target).is("#sendquery")) {	
						doSendQuery();						
						return false;
					} else if ($(event.target).is("#vcmeeting")) {						
						var url = "scgmmeeting.php";						
						$("#popdialog").load(url).dialog('open');
						return false;
					} else if ($(event.target).is("#login")) {	
						doLogin();						
						return false;
					} else if($(event.target).is("#playAudio") ) {						
						playAudio($(this).attr("mediaid"));
						return false;
					} else if ($(event.target).is("#calendarGo") ) {						
						getCalendar();
						return false;
					} else if ($(event.target).is("#playKartikAudio") ) {						
						playKartikAudio($(this).attr("file"), $(this).attr("duration"));
						return false;
					} else if ($(event.target).is("#playVideo") ) {						
						playVideo($(this).attr("file"), $(this).attr("duration"));
						return false;
					}
				});
			}

			function doSendQuery() {
				
				var name 		= 	'#name';
				var email 		= 	'#emailid';
				var country 	= 	'#country';
				var location 	= 	'#location';
				var question 	= 	'#question';
				
				var _name 		=	$(name).val();
				var _email 		=	$(email).val();
				var _country	=	$(country).val();
				var _location	=	$(location).val();
				var _question	=	$(question).val();
				
				if (_name.length==0) {
					$("#errorDiv").html("Name cannot be empty<br /><br />");
					$(_name).focus();
					return false;
				} else if (_email.length==0) {
					$("#errorDiv").html("Email cannot be empty<br /><br />");
					$(_email).focus();
					return false;
				} else if (_country.length==0) {
					$("#errorDiv").html("Select a country<br /><br />");
					return false;
				} else if (_question.length<10) {
					$("#errorDiv").html("Question not complete?<br /><br />");
					return false;
				} else {
					$("#queryFormDiv").html('<img src="images/loading5.gif" /><br />');
					$.ajax({   
						type: "POST", 
						url: "scgmtimes.post.php", 
						data: { 'action': 'sendquery', 'name': _name, 'email': _email, 'country': _country, 'location': _location, 'question': _question },
						complete: function(data){	
							$("#queryFormDiv").html(data.responseText);
							$("#queryFormDiv").dialog('open');
							return false;
						}	
					});				
				}
			}
			
			// Enter meeting
			function doLogin(id) {
					
				var name 		= 	'#name';
				var email 		= 	'#emailid';
				var country 	= 	'#country';
				var location 	= 	'#location';
				var message 	= 	'#message';
				
				var _name 		=	$(name).val();
				var _email 		=	$(email).val();
				var _country	=	$(country).val();
				var _location	=	$(location).val();
				var _message	=	$(message).val();
				
				if (_name.length==0) {
					$("#errorDiv").html("Name cannot be empty<br /><br />");
					$(_name).focus();
					return false;
				} else if (_country.length==0) {
					$("#errorDiv").html("Select a country<br /><br />");
					return false;
				} else {					
					$("#meetingFormDiv").html('<img src="images/loading5.gif" /><br />');
					$.ajax({   
						type: "POST", 
						url: "scgmtimes.post.php", 
						data: { 'action': 'vcmail', 'name': _name, 'email': _email, 'country': _country, 'location': _location, 'message': _message },
						complete: function(data){						
							var url = "newvcroom.html";						
							$("#meetingFormDiv").load(url).dialog('open');
							return false;
						}	
					});				
				}
			}
			
			// Play audio
			function playAudio(mediaid) {
				$("#audioPlayDiv").html('<img src="images/loading5.gif" /><br />');
				$.ajax({   
					type	: "POST", 
					url		: "scgmtimes.post.php", 
					data	: { 'action': 'playaudio', 'id': mediaid },
					complete: function(data){
						$("#audioPlayDiv").html(data.responseText);
						$("#audioPlayDiv").fadeIn(2000);				
					}	
				});	
			}
			
			// Play kartik audio
			function playKartikAudio(file, duration) {
				
				$("#audioPlayDiv").html('<img src="images/loading5.gif" /><br />');
				$.ajax({   
					type	: "POST", 
					url		: "scgmtimes.post.php", 
					data	: { 'action': 'playkartikaudio', 'file': file, 'duration': duration },
					complete: function(data){						
						$("#audioPlayDiv").html(data.responseText);
						$("#audioPlayDiv").fadeIn(2000);				
					}	
				});	
			}
			
			// Play video
			function playVideo(file, duration) {
				$("#audioPlayDiv").html('<img src="images/loading5.gif" /><br />');
				$.ajax({   
					type	: "POST", 
					url		: "scgmtimes.post.php", 
					data	: { 'action': 'playvideo', 'file': file, 'duration': duration },
					complete: function(data){						
						$("#audioPlayDiv").html(data.responseText);
						$("#audioPlayDiv").fadeIn(2000);				
					}	
				});	
			}
			
		/******************************************************************/		
		// Articles Page
			function minimizeArticleTOC() {
				scrollToTop();
				//$('#articlesDiv').animate({width:350}, 'medium');				
				$('#articlesDiv').css('width', 350);				
					fadeTOC();				
			}
			
			function fadeTOC() {
				if ($("#articlesDiv").width() > 385) {			
					$('#articlesDiv').css("background-color", "#EFECD6");
				} else {					
					$('#articlesDiv').css("background-color", 'transparent');
				}
			}
			
			function getArticle(documentid) {
				$("#articleDiv").html('<br /><img src="images/loading5.gif" />');
				$.ajax({   
					type	: "POST", 
					url		: "scgmtimes.post.php", 
					data	: { 'action': 'articleview', 'id': documentid },
					complete: function(data){					
						$("#articleDiv").html(data.responseText);			
					}
				});
			}
			
			
		/****************************************/
		// Audio Page		
			function minimizeAudioTOC() {
				$('#audiosDiv').animate({width:350}, 'slow');
				$("#col2").height($("#col1").height());
				$('#audioDiv').stickyfloat({ duration: 400, startOffset: 286, offsetY: 286 });				
			}
			
		
		/****************************************/
		// Calendar Page
		
			function getCalendar() {
			
				var scgmyear		= 	"#scgmyear";
				var scgmmonth		= 	"#scgmmonth";
			
				var _year		= 	$(scgmyear).val();
				var _month		=	$(scgmmonth).val();				
			
				$.ajax({   
						type: "POST", 
						url: "scgmtimes.post.php", 
						data: { 'action': 'calendarview', 'year': _year, 'month': _month},   
						complete: function(data){
							$("#calendar").html(data.responseText);   
							$("#calendar").fadeIn(2000);
							wtooltip();
							getCalendarListView();
						} 
				});

			}
		
			function getCalendarListView() {
			
				var scgmyear		= 	"#scgmyear";
				var scgmmonth		= 	"#scgmmonth";
			
				var _year		= 	$(scgmyear).val();
				var _month		=	$(scgmmonth).val();
			
				$.ajax({   
						type: "POST", 
						url: "scgmtimes.post.php", 
						data: { 'action': 'calendarlistview', 'year': _year, 'month': _month},   
						complete: function(data){
							$("#calendarlist").html(data.responseText);   
							$("#calendarlist").fadeIn(2000);
							if ($("#calendarlist").height() < 550) {
								$("#col1").height(790);																
							} else {								
								$("#col1").height($("#col2").height());
							}
							$('#calendar').stickyfloat({ duration: 400, offsetY: 300 });
						} 
				});

			}
		
			/****************************************/
	
		
	});