﻿$(window).bind('beforeunload', $.noop);

$(document).ready(function () {

	// adjust height in ribbon
	sqtRibbonHeightFix();
	
	$('.sqt-tabbed-zone').wpTabify();

	// site specific functions
	var path = window.location.pathname.toLowerCase();
	// blogs	
	if(path.indexOf('/blog') >= 0) {	
		sqtHideBlogAuthor(path);
		sqtShowBlogHeader(path);
		sqtShowBlogSidebar(path);
		sqtHideBlogAlerts();
	}	
	// products	
	else if(path.indexOf('/products/') >= 0) {	
		sqtStyleProductPages();
		sqtStyleProductsPage();
	}	
	
	// events
	sqtStyleEvents();
	
	// hide empty zones
	sqtHideEmptyZones();

	// get tweets
	 sqtGetTweets();
	 
	 // fix breadcrumbs
	 sqtFixBreadcrumb();
	        
});

function sqtFixBreadcrumb() {
	// hide crumbs to pages library
	$('.susqtech-breadcrumb span span a').each(function() {
		if($(this).text().trim() == "Pages") {
			$(this).parent().prev().hide();
			$(this).parent().hide();
		}				
	});
	// replace page name with page title
	if($('h1.page-title').size() > 0) {
		$('.susqtech-current-node').text($('h1.page-title').text());
	}
}

function sqtHideEmptyZones() {
	$('.page-title').each(function() {
		if($(this).text().trim() == "") {
			$(this).hide();
		}
	});
	/*
    if ($('.susqtech-right-sidebar').text().trim() == "") {
        // collapse rigth sidebar
        $('.susqtech-right-sidebar').hide();
        // expand middle
        var sidebarWidth = parseInt($('.susqtech-right-sidebar').css('width'));
        var middleWidth = parseInt($('.susqtech-middle').css('width'));
        $('.susqtech-middle').css('width', (sidebarWidth + middleWidth - 20) + 'px');
        $('.susqtech-middle-inner').css('margin', '0px 20px 20px 10px');
    }

    if ($('.susqtech-left-sidebar').text().trim() == "") {
        // collapse left sidebar
        $('.susqtech-left-sidebar').hide();
        // expand middle		
        var sidebarWidth = parseInt($('.susqtech-right-sidebar').css('width'));
        var middleWidth = parseInt($('.susqtech-middle').css('width'));
        $('.susqtech-middle').css('width', (sidebarWidth + middleWidth) + 'px');
        $('.susqtech-middle-inner').css('margin', '0px 20px 20px 10px');
    }
	*/
	
    // collapse any empty web parts
    //$('.s4-wpTopTable').each(function () {
    //    if ($(this).text().trim() == "")
    //        $(this).hide();
    // });

    // class custom web parts
    $('.susqtech-webpart').each(function () {
        $(this).parents('.s4-wpTopTable').addClass($(this).attr('class'));
    });

    // remove padding on web part zone
    $('.ms-SPZone').each(function () {
        $(this).attr('cellspacing', '0');
    });

    // hide empty sidebar nav
    if ($('.susqtech-sidebar-navigation div.ms-quicklaunch-navmgr').text().trim() != "") {
        $('.susqtech-sidebar-navigation').show();
    }
    if ($('.susqtech-sidebar-navigation .ms-quicklaunch-navmgr li').size() > 0) {
        $('.susqtech-sidebar-navigation').show();
    }
    if ($('.susqtech-sidebar-navigation .menu').size() > 0) {
        $('.susqtech-sidebar-navigation').show();
    }

}

function sqtGetTweets(){
/*
	$(".tweet").tweet({
		username: "susqtech",
		count: 1,
		refreshInterval: 30,
		loading_text: "Listening for tweets..."
	});

	$.Juitter.start({
		searchType:"fromUser", // needed, you can use "searchWord", "fromUser", "toUser"
		searchObject:"susqtech", // needed, you can insert a username here or a word to be searched for, if you wish multiple search, separate the words by comma.

		// The values below will overwrite the ones on the Juitter default configuration. 
		// They are optional here.
		// I'm changing here as a example only
		lang:"en", // restricts the search by the given language
		live:"live-9999999", // the number after "live-" indicates the time in seconds to wait before request the Twitter API for updates.
		placeHolder:"tweet", // Set a place holder DIV which will receive the list of tweets example <div id="juitterContainer"></div>
		loadMSG: "Listening for tweets....", // Loading message, if you want to show an image, fill it with "image/gif" and go to the next variable to set which image you want to use on 
		imgName: "loader.gif", // Loading image, to enable it, go to the loadMSG var above and change it to "image/gif"
		total: 1, // number of tweets to be show - max 100
		readMore: "Read it on Twitter", // read more message to be show after the tweet content
		nameUser:"image", // insert "image" to show avatar of "text" to show the name of the user that sent the tweet 
		openExternalLinks:"newWindow", // here you can choose how to open link to external websites, "newWindow" or "sameWindow"
                filter:"sex->*BAD word*,porn->*BAD word*,fuck->*BAD word*,shit->*BAD word*"  // insert the words you want to hide from the tweets followed by what you want to show instead example: "sex->censured" or "porn->BLOCKED WORD" you can define as many as you want, if you don't want to replace the word, simply remove it, just add the words you want separated like this "porn,sex,fuck"... Be aware that the tweets will still be showed, only the bad words will be removed
	});	
	*/
	$.jTwitter('susqtech', 1, function(posts){
	  for(var i=0; i<posts.length; i++){
	     $('.tweet').html(posts[i].text);
	  }
	});	
}

function sqtRibbonHeightFix() {
	rHeight = $('.susqtech-header').height();
	$('body #s4-workspace').css('padding-top',rHeight);		
}

function sqtStyleEvents() {

	$('.sqt-training-audience').parent().parent().addClass('sqt-training-audience-rollup');
	$(".sqt-training-audience-rollup div[id*='audience-id-']").each(function(e) {
		var id = $(this).attr('id').replace('audience-id-','');
		var links = "";
		$('.groupheader').each(function(e) {
			//console.log('"'+$(this).text().trim()+'"="'+id+'"');
			if($(this).text().trim() == id) {
				links = $(this).parent().find('ul').html();
			}
		});
		$(this).html(links);
	});
	
	// tabs
	$('.sqt-grey-tabs').tabs();
	if($('.course-detail').size() > 0) {
		$('.sqt-page-title').text($('.course-detail h2').text());
		$('.course-detail h2').hide();
	}
	
	var courseid = $('.susqtech-middle .course-id').text().trim();	
	$('.training-course a').attr('href',"/training/courses/pages/course-detail.aspx?courseid="+courseid);
	
	$('.susqtech-middle .course-information').each(function(e) {
		$.ajax({
		  url: "/training/courses/pages/course-detail.aspx?courseid="+courseid,
		  async: false,
		  context: document.body,
		  success: function(data){
		    $('.susqtech-middle .course-information').html($(data).find('.course-detail .sqt-grey-tabs'));
		    $('.sqt-grey-tabs').tabs();
		  }
		});
	});

	var instructorid = $('.susqtech-right-sidebar .instructor-id').text();		
	if(instructorid != null && instructorid != "") {
		sqtGetInstructorInfo(instructorid);
	}	
	
	var locationid = $('.location-id').text();		
	if(locationid != null && locationid != "") {
		sqtGetLocationInfo(locationid);
	}	

	var audience = $('.susqtech-middle .training-audience').text();		
	if(audience != null && audience != "") {
		sqtGetRelatedCourses(courseid, audience);
	}	
	
	if($('.item.sqt-event').size() > 0) {
		// class the event items parent container, for styling
		$('.item.sqt-event').first().parents('.cbq-layout-main > ul.dfwp-list').addClass('sqt-event-wrapper');
		$('.sqt-event-wrapper .groupheader').each(function(e) {
			var markup = $(this).text();			
			markup = markup.substring(markup.indexOf("(")+1, markup.indexOf(")")); 
			$(this).html(markup);
		});
	}
	
	$('.event-icon').click(function(e) {

		var show = true;
		
		if($(this).hasClass('off')) {
			$(this).removeClass('off');
		}
		else {
			$(this).addClass('off');
			show = false;			
		}
		var filter = "";
		if($(this).hasClass('training-event')) {
			filter = "SusQtechTrainingClass";
		}	
		else if($(this).hasClass('webinar-event')) {
			filter = "SusQtechWebinar";		
		}	
		else if($(this).hasClass('community-event')) {
			filter = "SusQtechCommunityEvent";		
		}	
		else if($(this).hasClass('conference-event')) {
			filter = "SusQtechConference";		
		}	
		
		if(show) {
			$('.'+filter).show();
		}
		else {
			$('.'+filter).hide();		
		}

	});
	
	
	// fix event dates, if not in edit mode	
	if($('.sqt-event-date').size() > 0 && $('.sqt-event-date input').size() == 0) {	
					
			$('.sqt-event-date').each(function(i){						
				var sd = new Date($(this).find('.start-date').text());
				var ed = new Date($(this).find('.end-date').text());

				var dateString = "";

				var ampm;
				var h = parseInt(sd.getHours());
				if(h > 12) {
					ampm = "PM";
					h = h - 12;
				}
				else {
					ampm = "AM";
				}
				
				var min = sd.getMinutes();
				if(min.toString().length == 1) {
					min = "0" + min.toString();
				}				
				/*
				if($('.ms-welcomeMenu a.ms-menu-a').size() <= 0) {
					if(h+4 > 12) {
						ampm = "PM";
						h = h - 12;
					}
					else {
						ampm = "AM";
					}
				
					dateString = (sd.getMonth()+1)+"/"+sd.getDate()+"/"+sd.getFullYear()+" "+(h+4)+":"+min+" "+ampm+ " to "; 				
				}
				else {
				*/
					dateString = (sd.getMonth()+1)+"/"+sd.getDate()+"/"+sd.getFullYear()+" "+h+":"+min+":"+ampm + " to ";
				/*}*/
				
				var h = parseInt(ed.getHours());
				var ampm;
				if(h > 12) {
					ampm = "PM";
					h = h - 12;
				}
				else {
					ampm = "AM";
				}
				
				var min = ed.getMinutes();
				if(min.toString().length == 1) {
					min = "0" + min.toString();
				}
				

				/*if($('.ms-welcomeMenu a.ms-menu-a').size() <= 0) {
					if(h+4 > 12) {
						ampm = "PM";
						h = h - 12;
					}
					else {
						ampm = "AM";
					}

					if(sd.getFullYear() == ed.getFullYear() && sd.getMonth() == ed.getMonth() &&
						sd.getDay() == ed.getDay()) {
						dateString += (h+4)+":"+min+" "+ampm; 							
					}
					else {
						dateString += (ed.getMonth()+1)+"/"+ed.getDate()+"/"+ed.getFullYear()+" "+(h+4)+":"+min+" "+ampm; 
					}										
				}
				else {
				*/
					if(sd.getFullYear() == ed.getFullYear() && sd.getMonth() == ed.getMonth() &&
						sd.getDay() == ed.getDay()) {
						dateString += h+":"+min+" "+ampm; 							
					}
					else {					
						dateString += (ed.getMonth()+1)+"/"+ed.getDate()+"/"+ed.getFullYear()+" "+h+":"+min+":"+ampm;
					}				
				/*}*/
																
				$(this).text(dateString); 
			});			
		}

}

var product;

function sqtStyleProductsPage() {
	try {
		$('.featured-product-tabs').tabs();
		if($('.featured-product').size() > 0) {		
			var featuredProduct = $('.featured-product .product-title').val().trim();
			
			$().SPServices({
				operation: "GetListItems",
				webURL: "/products",
				async: true,
				listName: "SusQtechProductScreenshots",
				CAMLQuery:	"<Query><Where><Eq><FieldRef Name='SusQtechProducts' /><Value Type='Choice'>"+featuredProduct+"</Value></Eq></Where></Query>",    
				CAMLRowLimit: "20",
				completefunc: function(xData,Status) {
				
					var image = "";
					var thumb = "";
					var ext = "";					
					var file = "";
					var title = "";
					var description = "";
					
					//$("#product-screenshots .tab-content-inner").html('');
					
				    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
				
				    	image = $(this).attr("ows_RequiredField").toLowerCase();
				    	ext = $(this).attr("ows_DocIcon").toLowerCase();	
				    	file = $(this).attr("ows_NameOrTitle").toLowerCase();	
				    	thumb = image.replace(file,'_t/'+file.replace('.'+ext,'_'+ext+'.jpg'));
				    	title = $(this).attr("ows_Title")+"";        	
				    	description = $(this).attr("ows_Description");        	
				    					    	
				        if(image != null) {
							$(".featured-product .sqt-product-screenshots").append('<a class="product-screenshot" title="'+description+'" href="/'+image+'"><img src="/'+thumb+'" /></a>');
						}
						
				    });				    				         
				    $("a.product-screenshot").fancybox({
						'transitionIn'	:	'elastic',
						'transitionOut'	:	'elastic',
						'speedIn'		:	600, 
						'speedOut'		:	200, 
						'cyclic'		: 	false,
						'showNavArrows'	:	true,
						'overlayShow'	:	false				    
				    });
						    
				}
			}); 
			
			$().SPServices({
				operation: "GetListItems",
				webURL: "/products",
				async: true,
				listName: "SusQtechProductVideos",
				CAMLQuery:	"<Query><Where><Eq><FieldRef Name='SusQtechProducts' /><Value Type='Choice'>"+featuredProduct+"</Value></Eq></Where></Query>",    
				CAMLRowLimit: "20",
				completefunc: function(xData,Status) {
				
					var image = "";
					var thumb = "";
					var ext = "";					
					var file = "";
					var title = "";
					var description = "";
					
					$("#product-videos .tab-content-inner").html('');
					
				    $(xData.responseXML).find("[nodeName='z:row']").each(function(i) {
				
				    	file = $(this).attr("ows_VideoUrl").split(',')[0];	
				    	thumb = $(this).attr("ows_VideoThumbnail");
				    	title = $(this).attr("ows_Title");        	
				    	description = $(this).attr("ows_VideoDescription");		    	
				    					    	
				        if(image != null) {
							$(".featured-product .sqt-product-videos").append(''+
								'<a class="product-video" title="'+description+'" href="#video-'+i+'">'+thumb+'<img src="/Style Library/susqtech-2010/i/product-video-overlay.png" class="video-overlay" /></a>'+
								'<div style="display:none;"><div id="video-'+i+'">'+												
								'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
									'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#4,0,0,0" '+
									'width="640" height="480" id="player-'+i+'" name="player-'+i+'">'+
									   '<param name="SRC" value="/Style Library/susqtech-2010/player.swf" />'+
									   '<param name="allowfullscreen" value="true" />'+
									   '<param name="allowscriptaccess" value="always" />'+
									   '<param name="flashvars" value="file='+file+'" />'+						
									'<embed '+
										'src="/Style Library/susqtech-2010/player.swf" '+
										'data="/Style Library/susqtech-2010/player.swf" '+
										'width="640" '+
										'height="480" '+
										'wmode="transparent" '+
										'allowfullscreen="true" '+
										'allowscriptaccess="always" '+								
										'flashvars="file='+file+'&autostart=false" /></object>'+
								'</div></div>');						
						}
																
				    });				    		
				    
					$('a.product-video').fancybox({
						'transitionIn'	:	'elastic',
						'transitionOut'	:	'elastic',
						'speedIn'		:	600, 
						'speedOut'		:	200, 
						'cyclic'		: 	false,
						'showNavArrows'	:	true,
						'overlayShow'	:	false				    
			    	});
			    	
				    							         
		   		}
			}); 				
			
			// class the rollups web part
			$('.product-rollup').parents('ul.dfwp-list').addClass('product-rollup-list');
			
		}
	}
	catch(err) {
	
	}
}


function sqtStyleProductPages() {
	try {
		if($('.ms-formfieldvaluecontainer').size() == 0 && $('#product').size() > 0) {		
			
			// top tabs
			$('#product-top-tabs').tabs();					
			
			// bottom tabs
			$('#product-bottom-tabs').tabs();
			
			product = $('#product-title').text().trim();
			
			// contact form
			/*$('.product-contact-form-input').focusin(function(e) {
				if($(this).val().toLowerCase() == $(this).attr('title')) {
					$(this).val('');
					$(this).css('color','#666666');
				}
			});
			$('.product-contact-form-input').focusout(function(e) {
				if($(this).val().toLowerCase() == '') {
					$(this).val($(this).attr('title'));
				}
			});
			$('#btnProductContactSubmit').click(function(e) {
				var name = $('#tbxProductContactName').val();
				var phone = $('#tbxProductContactPhone').val();
				var email = $('#tbxProductContactEmail').val();
				var valid = true;
				if(name.toLowerCase() == "" || name.toLowerCase() == "name") {
					$('#tbxProductContactName').css('color','#EC6C0E');
					valid = false;
				}
				if(phone.toLowerCase() == "" || phone.toLowerCase() == "phone") {
					$('#tbxProductContactPhone').css('color','#EC6C0E');
					valid = false;
				}
				if(email .toLowerCase() == "" || email.toLowerCase() == "email") {
					$('#tbxProductContactEmail').css('color','#EC6C0E');
					valid = false;
				}
				if(valid) {
					// submit form
				   $().SPServices({
				        operation: "UpdateListItems",
				        async: false,
				        batchCmd: "New",
				        listName: "Sales Contact Form",
				        valuepairs: [["Title", name], ["Phone", phone], ["Email", email]],
				        completefunc: function(xData, Status) {
				         	$('#product-contact-form-inner').text('Thank you for submitting the contact form. A SusQtech SharePoint Product Expert will contact your shortly.');
				        }
				    });				
				}
			});*/						

			sqtProcessProductScreenshots();
			sqtProcessProductVideos();
			sqtProcessProductReviews();
			if($("#product-faq .tab-content-inner .ms-rtestate-field").html().trim() == '') {
$("#product-faq").hide();
$("a[href='#product-faq']").parent().hide();
}		
		}
		else {
			// edit mode style accordingly		
			$('div[id*=product]').addClass('edit-mode');
		}
	}
	catch(e) {}

}

function sqtProcessProductReviews() {

	$().SPServices({
		operation: "GetListItems",
		webURL: "/products",
		async: false,
		CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='Review' /></ViewFields>",
		listName: "SusQtechProductReviews",
		CAMLQuery:	"<Query><Where><Eq><FieldRef Name='SusQtechProducts' /><Value Type='Choice'>"+product+"</Value></Eq></Where></Query>",    
		CAMLRowLimit: "20",
		completefunc: function(xData,Status) {
		
			var review = "";
			
			$("#product-reviews .tab-content-inner").html('');
			
		    $(xData.responseXML).find("[nodeName='z:row']").each(function(i) {
		
		    	review = $(this).attr("ows_Review");		    	
		    					    	
		        if(review != null) {
					$("#product-reviews .tab-content-inner").append(''+
						'<div>'+review+'</div>');						
				}
														
		    });				    								         
   		}
	}); 
		
	
	// hide empty review tabs
	if($("#product-reviews .tab-content-inner").html().trim() == '') {
		$("#product-reviews").hide();
		$("a[href='#product-reviews']").parent().hide();
	}
	
}


function sqtProcessProductVideos() {

	$().SPServices({
		operation: "GetListItems",
		webURL: "/products",
		async: true,
		listName: "SusQtechProductVideos",
		CAMLQuery:	"<Query><Where><Eq><FieldRef Name='SusQtechProducts' /><Value Type='Choice'>"+product+"</Value></Eq></Where></Query>",    
		CAMLRowLimit: "20",
		completefunc: function(xData,Status) {
		
			var image = "";
			var thumb = "";
			var ext = "";					
			var file = "";
			var title = "";
			var description = "";
			
			$("#product-videos .tab-content-inner").html('');
			
		    $(xData.responseXML).find("[nodeName='z:row']").each(function(i) {
		
		    	file = $(this).attr("ows_VideoUrl").split(',')[0];	
		    	thumb = $(this).attr("ows_VideoThumbnail");
		    	title = $(this).attr("ows_Title");        	
		    	description = $(this).attr("ows_VideoDescription");		    	
		    					    	
		        if(image != null) {
					$("#product-videos .tab-content-inner").append(''+
						'<a class="product-video" title="'+description+'" href="#video-'+i+'">'+thumb+'<img src="/Style Library/susqtech-2010/i/product-video-overlay.png" class="video-overlay" /></a>'+
						'<div style="display:none;"><div id="video-'+i+'">'+												
						'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
							'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#4,0,0,0" '+
							'width="640" height="480" id="player-'+i+'" name="player-'+i+'">'+
							   '<param name="SRC" value="/Style Library/susqtech-2010/player.swf" />'+
							   '<param name="allowfullscreen" value="true" />'+
							   '<param name="allowscriptaccess" value="always" />'+
							   '<param name="flashvars" value="file='+file+'" />'+						
							'<embed '+
								'src="/Style Library/susqtech-2010/player.swf" '+
								'data="/Style Library/susqtech-2010/player.swf" '+
								'width="640" '+
								'height="480" '+
								'wmode="transparent" '+
								'allowfullscreen="true" '+
								'allowscriptaccess="always" '+								
								'flashvars="file='+file+'&autostart=false" /></object>'+
						'</div></div>');						
				}
														
		    });				    		
		    
			$('a.product-video').fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	600, 
				'speedOut'		:	200, 
				'cyclic'		: 	false,
				'showNavArrows'	:	true,
				'overlayShow'	:	false				    
	    	});
	    	
			// hide empty video tabs			
			if($("#product-videos .tab-content-inner").html().trim() == '') {
				$("#product-videos").hide();
				$("a[href='#product-videos']").parent().hide();
			}	    							         
   		}
	}); 	
	
	
}

function sqtGetRelatedCourses(courseID, trainingAudience) {

	$().SPServices({
		operation: "GetListItems",
		webURL: "/",
		async: true,
		listName: "Training Courses",
		CAMLQuery:	"<Query><Where><Eq><FieldRef Name='Training_x0020_Audience' /><Value Type='Lookup'>"+trainingAudience+"</Value></Eq></Where>"+
						"<OrderBy><FieldRef Name='Title' Ascending='True' /></OrderBy>"+
					"</Query>",
		completefunc: function(xData,Status) {
		
			var title = "";
			var benefits = "";
			var id = "";
			var markup = "";				
			
			$(".susqtech-middle .related-course-information").html('<h3>Related Courses</h3>');
			
		    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
						
		    	title = $(this).attr("ows_Title");		    	
		    	id = $(this).attr("ows_ID");		    			    							
		    	benefits = $(this).attr("ows_Benefits");		    			    									    	
		    	
		    	if(id != courseID) {
		    	
				    markup += '<div class="related-course-title field"><a href="/training/courses/Pages/Course-Detail.aspx?courseid='+id+'">'+title+'</a></div>';
   				    markup += '<div class="related-course-benefits field">'+benefits+'</div>';
				    $(".susqtech-middle .related-course-information").append(markup);
				    markup = "";
			    }
		    });				 		    		    
		}
	}); 			
}


function sqtGetInstructorInfo(id) {

	$().SPServices({
		operation: "GetListItems",
		webURL: "/",
		async: true,
		listName: "Training Instructors",
		CAMLViewFields: "<ViewFields><FieldRef Name='Bio' /><FieldRef Name='FullName' />"+
			"<FieldRef Name='EMail' /><FieldRef Name='InstructorImage' /><FieldRef Name='JobTitle' />"+
			"<FieldRef Name='WebPage' />"+
			"</ViewFields>",
		CAMLQuery:	"<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>"+id+"</Value></Eq></Where></Query>",
		completefunc: function(xData,Status) {
		
			var fullname = "";
			var email = "";
			var image = "";					
			var jobtitle = "";
			var bio = "";
			var webpage = "";
			var instructorMarkup = "";
			
			$(".instructor-info").html('');
			
		    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
						
		    	fullname = $(this).attr("ows_FullName");		    	
		    	email = $(this).attr("ows_EMail");		    			    							
		    	image = $(this).attr("ows_InstructorImage");		    	
		    	jobtitle = $(this).attr("ows_JobTitle");        	
		    	bio = $(this).attr("ows_Bio");        	
		    	webpage = $(this).attr("ows_WebPage").split(',')[0];		    	
		    					    					
		    });				 
		    
			if(fullname != null && fullname != "") {
		    
			    instructorMarkup += '<div class="instructor-image">'+image+'</div>';
			    instructorMarkup += '<div class="instructor-info-right"><div class="instructor-name">'+fullname+'</div>';
			    instructorMarkup += '<div class="instructor-jobtitle">'+jobtitle+'</div>';		    		    
	   		    instructorMarkup += '<div class="instructor-email"><a href="mailto:training@susqtech.com">email</a></div>';
			    instructorMarkup += '<div class="instructor-webpage"><a href="'+webpage+'">blog</a></div></div>';
			    instructorMarkup += '<div class="instructor-bio">'+bio+'</div><div class="clear"></div>';		       		    
		    }
		    else {
		    	instructorMarkup += 'An instructor has not been assigned to this class.';
		    }
		    $(".instructor-info").html(instructorMarkup);
		}
	}); 			
}

function sqtGetLocationInfo(id) {

	$().SPServices({
		operation: "GetListItems",
		webURL: "/",
		async: true,
		listName: "Training Locations",
		CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Address' /><FieldRef Name='Directions' />"+
			"</ViewFields>",
		CAMLQuery:	"<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>"+id+"</Value></Eq></Where></Query>",
		completefunc: function(xData,Status) {
		
			var title = "";
			var address = "";
			var locationMarkup = "";				
			var directions = "";
			
			$(".location-info").html('');
			
		    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
						
		    	title = $(this).attr("ows_Title");		    	
		    	address = $(this).attr("ows_Address");		    			    							
		    	directions = $(this).attr("ows_Directions");
		    	if(directions != null && directions != "") {
			    	directions = '<a href="'+directions.split(',')[0]+'">'+ directions.split(',')[1]+'</a>';
			    }	
		    					    					
		    });				    				         
		    
		    if(address != null && address != "") {
		    
			    locationMarkup += '<div class="location-title field">'+title+'</div>';
			    locationMarkup += '<div class="location-address field">'+address+'</div>';		    		    
			    locationMarkup += '<div class="location-address field">'+directions+'</div>';		    
			    		    			    
			    try {
			    
					var map = new GMap2(document.getElementById("map_canvas"));
					var geocoder = new GClientGeocoder();
					
					function showAddress(address) {
					  geocoder.getLatLng(
					    address,
					    function(point) {
					      if (!point) {
					        alert(address + " not found");
					      } else {
					        map.setCenter(point, 13);
					        var marker = new GMarker(point);
					        map.addOverlay(marker);
					
					        // As this is user-generated content, we display it as
					        // text rather than HTML to reduce XSS vulnerabilities.
					        //marker.openInfoWindow(document.createTextNode(address));
					      }
					    }
					  );
					}
					showAddress(address);
				}
				catch(err) {}	    
				
			}
			else {
			    locationMarkup += '<div class="location-address field">'+directions+'</div>';
		    	// hide map
		    	$('#map_canvas').hide();		   
			}
			
			$(".location-info").html(locationMarkup);
		}
	}); 		

}

function sqtProcessProductScreenshots() {

	$().SPServices({
		operation: "GetListItems",
		webURL: "/products",
		async: true,
		listName: "SusQtechProductScreenshots",
		CAMLQuery:	"<Query><Where><Eq><FieldRef Name='SusQtechProducts' /><Value Type='Choice'>"+product+"</Value></Eq></Where></Query>",    
		CAMLRowLimit: "20",
		completefunc: function(xData,Status) {
		
			var image = "";
			var thumb = "";
			var ext = "";					
			var file = "";
			var title = "";
			var description = "";
			
			$("#product-screenshots .tab-content-inner").html('');
			
		    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
		
		    	image = $(this).attr("ows_RequiredField").toLowerCase();
		    	ext = $(this).attr("ows_DocIcon").toLowerCase();	
		    	file = $(this).attr("ows_NameOrTitle").toLowerCase();	
		    	thumb = image.replace(file,'_t/'+file.replace('.'+ext,'_'+ext+'.jpg'));
		    	title = $(this).attr("ows_Title")+"";        	
		    	description = $(this).attr("ows_Description");        	
		    					    	
		        if(image != null) {
					$("#product-screenshots .tab-content-inner").append('<a class="product-screenshot" title="'+description+'" href="/'+image+'"><img src="/'+thumb+'" /></a>');
				}
				
		    });				    				         
		    $("a.product-screenshot").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	600, 
				'speedOut'		:	200, 
				'cyclic'		: 	false,
				'showNavArrows'	:	true,
				'overlayShow'	:	false				    
		    });
		    
			// hide empty video tabs			
			if($("#product-screenshots .tab-content-inner").html().trim() == '') {
				$("#product-screenshots").hide();
				$("a[href='#product-screenshots']").parent().hide();
			}
		    
		}
	}); 		
		

}

function sqtShowBlogSidebar(path) {
	try {
		// show sidebar if on a blog page
		if(path.indexOf('http://www.susqtech.com/blogs/ui') >= 0 ||
			path.indexOf('http://www.susqtech.com/blogs/dev') >= 0) {
			$('div.sqt-main').css('background','#E9E7DB');
			$('div.sqt-main').css('width','818px');
			$('div.sqt-main-footer').css('background','url("/Style Library/susqtech-2010/i/page-sidebar-wide.png") repeat-y scroll left top transparent');
			$('.ms-blogRightZone table:first').wrap('<div class="blog-sidebar-inner">');
			$('.blog-sidebar-inner').wrap('<div class="blog-sidebar">');
		}
	}
	catch(e) {}
}
function sqtHideBlogAlerts() {
	$('.ms-blogrss').each(function() {
	
		if($(this).attr('id') != "BlogRSSMain") {			
			$(this).hide();
		}
	});
}

function sqtShowBlogHeader(path) {
	try {
		// show blog header if in the blog site
		if(path.indexOf('http://www.susqtech.com/blogs') >= 0) {
			$('h1.sqt-logo a').addClass('blog-logo');
			$('h1.sqt-logo').addClass('sqt-logo-blog');
		}
	}
	catch(e) {}
}

function sqtHideBlogAuthor() {
	try {
		$('a[href*=/_layouts/userdisp.aspx?ID=]').each(function() {
			$(this).parent().html($(this).text());
		});
		$('div.ms-CommentFooter nobr span').each(function() {
			if($(this).text() == "System Account") {
				$(this).text('Anonymous');
			}
		});
	}
	catch(e) {}
}

(function($){
	$.fn.wpTabify = function(){
		if($('.ms-WPAddButton').size() == 0){
			return this.each(function(i){
				var tabList = $('<ul class="wpt-ui-tabs-nav"/>');
				var panels = $('<div class="wpt-ui-tabs-wrapper"/>');
				$(this).find('.s4-wpTopTable,td[id^="MSOZoneCell_"] > table').each(function(j){
					$(tabList).append('<li><a href="#ui-tab-panel' + i + j + '">' + $(this).find('h3.ms-WPTitle').text() + '</a></li>');
					var thisPanel = $('<div id="ui-tab-panel' + i + j + '" class="wpt-ui-tabs-panel"/>');
					var panelContents = $(this).detach();
					$(thisPanel).append($(panelContents).find('.ms-WPBody').html());
					$(panels).append(thisPanel);
				});
				if($(tabList).find('li').size() > 0){
					$(this).prepend(panels);
					$(this).prepend(tabList);
					$(this).tabs();
				}
			});
		}
		else{
			return false;
		}
	};
})(jQuery);

