﻿var converter = new Showdown.converter();

$(document).ready(function(){

	// GLOBAL READMODE/EDITMODE
	// toggle editmode and readmode classes per editing status
		if($('#MSOLayout_InDesignMode').val() == '1') 
			$('html').addClass('editmode');
		else
			$('html').addClass('readmode');
	
	// GLOBAL DEV & TEST
	// use dev and test watermarks in the background when not in prod
		if(window.location.href.toLowerCase().indexOf("http://dev") != -1){
			$('html').addClass('dev');
		} else if(window.location.href.toLowerCase().indexOf("http://test") != -1){	
			$('html').addClass('test');
		}

	
	//SEARCH	
	$('#absoluteSearch input').keypress(function(event) {
		
		if (event.keyCode==13){
			searchThis($(this).val());
			return(false);
		}
	});

	$('#absoluteSearch a').click(function() {
		searchThis($(this).siblings('input').eq(0).val());
		return(false);
	});
	
	// Search box effects //	
	
	$("#SearchTextbox").focus ( 
		function() { 
			$(this).siblings("a").css("backgroundImage", "url(/style%20library/images/flow-search-button-hover-18x21.png)");
		}
	);
	
	$("#SearchTextbox").blur (  
		function() { 
			$(this).siblings("a").css("backgroundImage", "none");
		}
	);
	
	// Lightbox //
	$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'mychk', opacity: '0.75', showTitle: true, autoplay: true});
	
	// Markdown / Showdown //
	if( $( ".markdown" ).size() > 0 ) {
		$( ".markdown" ).each( function( i ){
			$(this).html( converter.makeHtml( $(this).html() ) );
		});
	}
	
	//Image Gallery Navigation
	var activeSet = false;	
	$('ul.imageGalleryCategoryList li.filterItem').removeClass('active').each(function(i){
		if(window.location.search == $(this).find('a').eq(0).attr('href')){
			$(this).addClass('active');
			activeSet = true;
		}
	});
	if (!activeSet){
		if($('ul.imageGalleryCategoryList li.filterItem').size() == 1){
			$('ul.imageGalleryCategoryList li.filterItem').eq(0).addClass('active');
		}else{
			$('ul.imageGalleryCategoryList li.allImages').eq(0).addClass('active');
		}
	}

	//links external to the site should open up in a new tab/window
	$("a.rtIn:not([href^='/'])").attr("target","_blank");
	$("a.rmLink:not([href^='/'])").attr("target","_blank");
	
});

$(function() {
	if ( $('.ie6').length == 1 ){
		var zIndexNumber = 10000;
		$('div').each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});
	}
});

function searchThis(keywordString){
	window.location = "/Search/Pages/Results.aspx?k=" + keywordString; //s=All%20Sites&
}

