﻿// Wait for the DOM to load before we execute...

$(function($) {

	var spn = $("#ctl00_sel_IAPageName").text().trim();
	var sid = $("#ctl00_sel_IAListitemID").text().trim();
	var sln = $("#ctl00_sel_IAListName").text().trim();
	var six = $("#ctl00_sel_IAPathItem").text().trim();
	var spx = $("#ctl00_sel_IAPathParent").text().trim();
	var splitndx = six.toLowerCase().split("/");
	var vFldr = splitndx[0]+'/'+splitndx[1]

	/****** ACTIVATE PANEL MENU TABS *****/
	$("#iaPanelTabs ul.ia-Tabs").tabs("#iaPanelTabs div.ia-Panes > div.ia-LeftNavMenu", {
		initialIndex: 0
	});
	
	/****** ACTIVATE PANEL MENU TOOLTIPS *****/
	$("#iaPanelTabs ul.ia-tooltip-items li div.ia-tooltip-link").tooltip({
		effect: 'fade',
		fadeOutSpeed: 100,
		predelay:300,
		position: "center right",
		offset: [-40, 10]
	});
	
	$("div.ia-QLinkItems ul.ia-tooltip-items li.selected").each(function(){
		if($(this).attr('class').indexOf('ia-PanelPage')>-1){
			
		} else if($(this).attr('class').indexOf('ia-PanelNav3')>-1){
			$("li[ndx='"+spx+"']").addClass('child-selected');
		}
	});

	/****** START - ACTIVATE PAGE RESOURCE LINKS *****/
    $(".ia-accordion-list").tabs("table.ia-resource-detail", {
    	tabs: 'table.ia-resource-header',
    	effect: 'slide',
    	event:'click',
    	initialIndex: 0});
    	
   	$("a.ia-ResourcePreview-Link").live('click',function(event){
   		//event.preventDefault();
		if($("div#iaResourcePreview").length != "0"){$("div#iaResourcePreview").remove();}
		var vFrame = PreviewResourceDocumentFrame($(this).attr('accesskey'), $(this).attr('type'), $(this).attr('ID'));
		$("div.ia-ResourcePreviewContainer").append(vFrame); //build frame //
		$("#iaResourcePreview").overlay({top:100,mask:{color:'#ffffff',loadSpeed:100,opacity:0.3},closeOnClick:false,load:true});
		$("a.close").attr('title','Close Window');
		if(($.browser.msie==true)&&($.browser.version == '8.0')){
			$("a.close").css('top','0px');
		}
	});
	
	//when dialog is closed remove diviaResourcePreview from page.//
	$("div#iaResourcePreview .close").live( "click", function(event, ui) {
		$("div#iaResourcePreview").remove();
	});
	/****** END - ACTIVATE PAGE RESOURCE LINKS *****/

	
	/***** if not in edit mode, move panel content *****/
	if($("#MSOLayout_InDesignMode").attr('value')==""){
		$("div#iaPanelAddedContent").append($("table.ms-rteTable-9"));
		$("div#iaPanelAddedContent").append($("div#iaPanelContent"));
	}
		
	if(spn == 'HOMEPAGE'){
		$("#s4-topheader2 div.menu-horizontal ul.root li.static:eq(0)").addClass('selected');
		$("#iaPanelNavigation li:gt(7)").hide();
		$("#iaQLinkContent1").show();
		if(window.location.pathname.endsWith('AllPages.aspx')){
			$("#s4-leftpanel").hide();
			$("#MSO_ContentTable").css('margin-left','0px');
			$("#ia-pageMarginLocationLinks").css('margin-left','10px');
		}
	} else {
		// SOCIAL NETWORKING LINKS //
		if(location.protocol == 'http:'){
			// move links to top of page //	
			var spt = $("#ctl00_sel_IAPageTypeID").text().trim();
			if(spt==1){	
				$("div#iaSocialMediaLinksContainer").append($("table.iaSocialLinksList"));
				var thisPage = window.location.href
				var aryFb = {href:thisPage, layout:'standard', show_faces:false, width:'450', action:'like', colorscheme:'light', height:'35'};
				var strFb = jQuery.param(aryFb);
				$("#iaSocialLink-facebook iframe").attr('src','http://www.facebook.com/widgets/like.php?' + strFb);
			
				var vPLnk = jQuery.param({ln:sln,id:sid}); 
				$("a#iaPrintArticleLink").attr('href','/utilities/printing/printer-friendly.htm?'+vPLnk);
			}
			// ***** SOCIAL MEDIA LINKS - END ***** //		
		}
		
		if(sln == 'Resources'){
			$("#s4-topheader2 div.menu-horizontal ul.root li.static:eq(6)").addClass('selected');
			$("#iaQLinkTab1").text("Resources");
		} else if (sln == 'Pages'){
			if(vFldr == 'pages/about-us'){
				$("#s4-topheader2 div.menu-horizontal ul.root li.static:eq(1)").addClass('selected');
				$("#iaQLinkTab1").text("Information");
			} else if(vFldr == 'pages/news'){
				$("#s4-topheader2 div.menu-horizontal ul.root li.static:eq(2)").addClass('selected');
				$("#iaQLinkTab1").text("News");
			} else if(vFldr == 'pages/get-involved') {
				$("#s4-topheader2 div.menu-horizontal ul.root li.static:eq(3)").addClass('selected');
				$("#iaQLinkTab1").text("Information");
			} else if(vFldr == 'pages/scholarships') {
				$("#s4-topheader2 div.menu-horizontal ul.root li.static:eq(4)").addClass('selected');
				$("#iaQLinkTab1").text("Information");
			} else if(vFldr == 'pages/partners') {
				$("#s4-topheader2 div.menu-horizontal ul.root li.static:eq(5)").addClass('selected');
			} else if(vFldr == 'pages/student-center') {
				$("#s4-topheader2 div.menu-horizontal ul.root li.static:eq(7)").addClass('selected');
			} else if(vFldr == 'pages/career-center') {
				$("#s4-topheader2 div.menu-horizontal ul.root li.static:eq(8)").addClass('selected');
				$("#iaQLinkTab1").text("Information");
			} else if(vFldr == 'pages/donate') {
				$("#s4-topheader2 div.menu-horizontal ul.root li.static:eq(9)").addClass('selected');

			} 
		}
	}

	// ***** WIKIPAGE NEW PAGE LINK - START ***** //
	if($("#idHomePageNewWikiPage").length>0){
		var sOC = $("#idHomePageNewWikiPage").attr('onClick');
		$("#idHomePageNewWikiPage").attr('onClick', sOC.replace('CreateWebPage', 'IA_ContentTypes/CreateIAWikiPage'));
		var shref = $("#idHomePageNewWikiPage").attr('href');
		$("#idHomePageNewWikiPage").attr('href', shref.replace('CreateWebPage', 'IA_ContentTypes/CreateIAWikiPage'));
	}
	// ***** WIKIPAGE NEW PAGE LINK - END ***** //
	
	// ***** LOGIN DIALOG - Start ***** //
	$("#iaWebSrvr").attr('title',$("meta[name='ia_server']").attr('content'));
	// ***** LOGIN DIALOG - END ***** //
	

	// ***** LOGIN DIALOG - Start ***** //
	//$("#ctl00_IdWelcome_ExplicitLogin").bind('click', function(event) {
 	//	event.preventDefault()
 	//	var vhref = $(this).attr('href');
 	//	SP.UI.ModalDialog.ShowPopupDialog(vhref);
	//});
	// ***** LOGIN DIALOG - END ***** //
		
	// ***** VIMEO MOVIE - Start *****//
	// build the vimeo ifram within a vimeo-movie div based on link properties //
	$("a.vimeo-link").live('click',function(){
		$(this).after(VimeoMovieFrame($(this).attr('href').replace('#',''), $(this).attr('title'))); //build frame //
		$("div.vimeo-movie").overlay({top:260,	mask:{color:'#fff',loadSpeed:200,opacity:0.3},closeOnClick:false,load:true}); //play movie in overlay//
		$("a.close").attr('title','Close Window');
	});
	//when movie is closed remove div.vimeo-movie from page.//
	$("div.vimeo-movie .close").live( "click", function(event, ui) {
		$("div.vimeo-movie").remove();
	});
	// fucntion - returns required html //
	var VimeoMovieFrame = function(MovieID, MovieTitle) {
		var vFrm= "<div class='vimeo-movie' id='"+MovieID+"' title='"+MovieTitle+"'><iframe src='http://player.vimeo.com/video/"+MovieID+"?title=0&amp;byline=0&amp;portrait=0&amp;color=8B1515' width='400' height='300' frameborder='0'></iframe></div>"
	   	return vFrm
	};
	// ***** VIMEO MOVIE - End *****//

	/* Accordion */
	var vtndx = 0
	if(vFldr == 'pages/donate'){vtndx = 3}
    $(".ia-accordion-items").tabs(".ia-accordion-items div.pane", {tabs: 'h3', effect: 'slide', initialIndex: vtndx});
    
    //* TABS *//
	$("#iaArticleTabsList ul.ia-Tabs").tabs("#iaArticleTabsList div.ia-Panes > div.ia-Pane", {
			initialIndex: 0
	});

    
    $("div.ia-SlideTabs").tabs("div.ia-SlideImages > div", {
		effect: 'fade',
		fadeOutSpeed: "slow",
		rotate: true
	}).slideshow();
	
	/****** HIDE PANEL MENU TABS ON SOME ADMIN PAGES *****/
	var sPath = window.location.pathname.toLowerCase();
	var hidePanelMenu=false
	if(sPath.indexOf('/forms/')>0){
		hidePanelMenu=true;
	} else if(sPath.indexOf('lists/')>0){
		hidePanelMenu=true;
	} else if(sPath.indexOf('_layouts')>0){
		hidePanelMenu=true;
	}
  	if(hidePanelMenu==true){
		$("#s4-leftpanel").hide();
		$("#ia-pageMarginLocationLinks").css('margin-right', '10px');
		$("#MSO_ContentTable").css('margin-right', '0px');
	}
});

$(window).load(function () {
	/****** ACTIVATE TOOLTIPS *****/
	if($("#iaPanelTabs div.ms-searchsummarybody").length>0){
		$("div.ms-searchsummarybody div.ms-searchsummaryTitle").tooltip({
			effect: 'fade',
			fadeOutSpeed: 100,
			predelay:300,
			position: "center right",
			offset: [-160, -60]
		});
		
		/****** HIGHLIGHT ALTERNATE ROWS *****/
		$("div.ms-searchsummarybody div.ms-searchsummaryTitle:odd").addClass("ia-tooltip-altrow");
	}
});

// ***** REQUIRED FUNCTIONS ***** //
// ***** MODAL DIALOG - Start *****//
// fucntion - returns required html //
var PreviewResourceDocumentFrame = function(path, type, vID) {
	// find thumbnail image to determin orientation //
	var vFrm = ""
	var vImgW = $("img.ia-resource-image")[0].width
	var vImgH = $("img.ia-resource-image")[0].height
	var vTopM = "50px;"
	//var vImgTM = 
	var vcls = "ia-preview-vrt"
	if(vImgW > vImgH){vcls = 'ia-preview-hrz'}
	if(type == 'pdf'){path = path+"#toolbar=0&amp;navpanes=0&amp;scrollbar=1;page=3"}

	if(type == 'pdf'){
		var vFrm = "<div id='iaResourcePreview' class='ia-Resource-Preview "+vcls+"'><iframe class='ia-resource-preview-frame' src='"+path+"' frameBorder='0' title='Preview' height='100%' width='100%'></iframe></div>"
	} else if((type == 'doc')||(type =='docx')) {
		path = path+"#toolbar=0&amp;navpanes=0&amp;scrollbar=1"
		var vFrm = "<div id='iaResourcePreview' class='ia-Resource-Preview "+vcls+"'><iframe class='ia-resource-preview-frame' src='"+path+"' frameBorder='0' title='Preview' height='100%' width='100%'></iframe></div>"
	} else if((type == 'gif')||(type == 'jpg')||(type == 'png')) {
		var vImgSt = 'margin-top:'+vTopM+';'
		var vFrm = "<div id='iaResourcePreview' class='ia-Resource-Preview ia-preview-img"+vcls+"' style='"+vImgSt+"'><img class='ia-resource-preview-frame' src='"+path+"' Border='0'></img></div>"
	} else if((type == 'ppt')||(type =='pptx')) {
		var vPath = path
		vPath = "/utilities/preview/preview-ppt.aspx?xi=media/"+vPath+"/ppt_"+vID
		var vFrm = "<div id='iaResourcePreview' class='ia-Resource-Preview ia-preview-ppt'><iframe class='ia-resource-preview-frame' src='"+vPath+"' frameBorder='0' title='Preview' height='100%' width='100%'></iframe></div>"
	} else {
		var vPath = location.pathname
		vPath = vPath.replace("Resources.aspx","");
		vPath = "/Utilities/DEV/PowerPointPreview.aspx?xi=media"+vPath+"ppt_"+vID
		var vFrm = "<div id='iaResourcePreview' class='ia-Resource-Preview ia-preview-ppt'><iframe class='ia-resource-preview-frame' src='"+vPath+"' frameBorder='0' title='Preview' height='100%' width='100%'></iframe></div>"
	}
	return vFrm	
};
// ***** MODAL DIALOG - End *****//
// ***** Cookie - Start *****//
jQuery.cookie = function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
// ***** Cookie - End *****//


// *****  - Start *****//
// *****  - End *****//



