var resizeText = function (size) {   
	var myCookie = jQuery.cookie('fontSize', size); 
	redrawFonts(size);
} 

var redrawFonts = function(size) {
	$body = jQuery("body").removeClass('resize1');
	$body.removeClass('resize2');
	$body.removeClass('resize3');
	$body.addClass('resize' + String(size));
}

initializePage = function (id, primaryid) {
	
	
	/*jQuery('area[alt]').qtip(
   {
      content: {
         attr: 'alt'
      },
      style: {
         classes: 'ui-tooltip-tipsy ui-tooltip-shadow'
      }
   });*/
	 
	offsetList = { 
   		"Develop": { 	"offsetImage": "#solutionsImage", "myXoffset": 220, 	"myYoffset": 67},
   		"Analyze": { 	"offsetImage": "#solutionsImage", "myXoffset": -142, 	"myYoffset": 0},
      	"Design": { 	"offsetImage": "#solutionsImage", "myXoffset": 220, 	"myYoffset": 0},
      	"Implement": { 	"offsetImage": "#solutionsImage", "myXoffset": -90, 	"myYoffset": 160},
      	"Evaluate": { 	"offsetImage": "#solutionsImage", "myXoffset": -144, 	"myYoffset": 72},
      	
      	"Knowledge": { 	"offsetImage": "#advisoryImage", "myXoffset": -117, "myYoffset": 10},
      	"Motivation": { "offsetImage": "#advisoryImage", "myXoffset": 248, "myYoffset": 106},
      	"Resources": { 	"offsetImage": "#advisoryImage", "myXoffset": -117, "myYoffset": 100},
      	
      	"BasicTraining": { 			"offsetImage": "#learningImage", "myXoffset": -53, "myYoffset": 78},
      	"JobSpecificTraining": { 	"offsetImage": "#learningImage", "myXoffset": 103, "myYoffset": 78},
      	"AdvancedTraining": { 		"offsetImage": "#learningImage", "myXoffset": 280, "myYoffset": 78},
      	"HireToRetire": { 			"offsetImage": "#learningImage", "myXoffset": 263, "myYoffset": -38},
      	
      	"UpdateEdit": { 	"offsetImage": "#policiesImage", "myXoffset": 232, "myYoffset": 78},
      	"DevelopBlue": { 	"offsetImage": "#policiesImage", "myXoffset": 232, "myYoffset": 9},
      	"Audit": { 			"offsetImage": "#policiesImage", "myXoffset": -133, "myYoffset": 7},
      	"Maintain": { 		"offsetImage": "#policiesImage", "myXoffset": -133, "myYoffset": 8},
      	"Train": { 			"offsetImage": "#policiesImage", "myXoffset": -133, "myYoffset": 126},
      	
      	"SupportServices": { 	"offsetImage": "#programImage", "myXoffset": 220, "myYoffset": 1},
      	"DesignFacilitation": { "offsetImage": "#programImage", "myXoffset": 220, "myYoffset": 137},
      	"Compliance": { 		"offsetImage": "#programImage", "myXoffset": -145, "myYoffset": 137},
      	"Management": { 		"offsetImage": "#programImage", "myXoffset": -145, "myYoffset": 1}
    }
	 
	 
   jQuery('area').each(function()
   {
      var $this = jQuery(this);
      var thisRel = $this.attr('Rel');
      
     $this.qtip(
      {
         content: {
					text: jQuery('#'+thisRel)
				 },
         style: {
            classes: 'ui-tooltip-light ui-tooltip-shadow',
				tip: {
					 corner: true
				}
         },
				 position: {
					 target: jQuery(offsetList[thisRel].offsetImage),
					 my: 'top left',
					 at: 'top left',
					 adjust: {
						 x: offsetList[thisRel].myXoffset,
						 y: offsetList[thisRel].myYoffset
					}
				 }
      })
   })
 
   // Make sure it doesn't follow the link when we click it
   .click(function(event) { event.preventDefault(); });
	 
	 //jQuery(".brochureDownload").parents(".rightside_content").css("paddingLeft", "5px");
	 
	 /* FONT SIZE */
	/*var gp = readCookie('customfontsize');
	var sizeInc = 'user3'; 
	var sizeDec = 'user2';
	if (gp) {
		changeFontSize(gp);
	} else {
		createCookie('customfontsize','user1',7)
	}

	if(jQuery('a#resetlink')) {
		jQuery("a#resetlink").attr('onclick', 'javascript:changeFontSize(\'user1\')');
	}
	if(jQuery('a#declink')) {
		jQuery("a#declink").attr('onclick', 'javascript:changeFontSize(\''+ sizeDec +'\')');
	}
	if(jQuery('a#inclink')) {
		jQuery("a#inclink").attr('onclick', 'javascript:changeFontSize(\''+ sizeInc +'\')');
	}*/
	
	
	
	var pushpane = function(e,idx){	
		location.hash = 'Pane'+(idx+1);
	}
	
	/* TABS */
	jQuery("#tabbedContent > div.tabs").tabs("#tabbedContent > div.panes > div",{ onClick: pushpane }); 
	
	jQuery('a[href$=".pdf"]').addClass("pdflink");
	
	
	if (id == 1) {
		jQuery(".scrollable").scrollable({circular: true}).autoscroll({ autoplay: true, interval: 5000 });
		
		var lastClass = 'orange';
		
		
		
		
		/*var config = {    
			over: rollover, // function = onMouseOver callback (REQUIRED)    
			timeout: 500, // number = milliseconds delay before onMouseOut    
			out: rollout // function = onMouseOut callback (REQUIRED)    
		};*/
		
		/*jQuery(".marquee li").hover(rollover, rollout);*/
		
		jQuery(".marquee li").mouseover(function(e){
			var currClass = jQuery(this).attr("class");
			jQuery(".marquee_over").hide();
			jQuery("."+currClass+"_over").show();
			if (currClass == 'orange') {
				jQuery("."+currClass).stop().animate({
					marginLeft: 45
				}, 300);
			}
			if (currClass == 'green' || currClass == 'blue') {
				jQuery(".marquee ul").stop().animate({
					marginLeft: 10
				}, 300);
				jQuery("."+currClass).stop().animate({
					marginRight: 89
				}, 300);
			}
			if (currClass == 'pink') {
				jQuery(".marquee ul").stop().animate({
					marginLeft: 10
				}, 300);
			}
			lastClass = currClass;
		});
		
		jQuery(".marquee_over").mouseout(function(e){
			jQuery("."+lastClass+"_over").hide();
			if (lastClass == 'orange') {
				jQuery("."+lastClass).stop().animate({
					marginLeft: 0
				}, 300);
			}
			if (lastClass == 'green' || lastClass == 'blue') {
				jQuery(".marquee ul").stop().animate({
					marginLeft: 40
				}, 300);
				jQuery("."+lastClass).stop().animate({
					marginRight: 0
				}, 300);
			}
			if (lastClass == 'pink') {
				jQuery(".marquee ul").stop().animate({
					marginLeft: 40
				}, 300);
			}
		});
		
		
		
		jQuery(".orange_over").click(function() {
			//document.location.href = 'http://www.tdshou.com/Solutions/Advisory_Services/';
			document.location.href = 'http://www.tdshou.com/Solutions/Advisory_Services/';
		});
		
		jQuery(".green_over").click(function() {
			//document.location.href = 'http://www.tdshou.com/Solutions/Learning_Development/';
			document.location.href = 'http://www.tdshou.com/Solutions/Learning_Development/';
		});
		
		jQuery(".blue_over").click(function() {
			//document.location.href = 'http://www.tdshou.com/Solutions/Policies_Procedures/';
			document.location.href = 'http://www.tdshou.com/Solutions/Policies_Procedures/';
		});
		
		jQuery(".pink_over").click(function() {
			//document.location.href = 'http://www.tdshou.com/Solutions/Program_Management/';
			document.location.href = 'http://www.tdshou.com/Solutions/Program_Management/';
		});
		
		
	}
}

var txts = document.getElementsByTagName('TEXTAREA'); 
for(var i = 0, l = txts.length; i < l; i++) {
	if(/^[0-9]+$/.test(txts[i].getAttribute("maxlength"))) { 
		var func = function() { 
			var len = parseInt(this.getAttribute("maxlength"), 10); 

			if(this.value.length > len) { 
				alert('Maximum length exceeded: ' + len); 
				this.value = this.value.substr(0, len); 
				return false; 
			} 
		}

		txts[i].onkeyup = func;
		txts[i].onblur = func;
	} 
} 

//contact us popup code
function clearContactForm() {
	jQuery('#siteCover').css('display', 'none');
	jQuery('#contactUsForm').css('display', 'none');
	jQuery('body').css('overflow', 'auto');
	jQuery('#contactUsTY').css('display', 'none');	
}
function openContactForm() {		
	jQuery('#contactUsForm').css('display', 'block');
	jQuery('#siteCover').css('display', 'block');
	/*jQuery('body').css('overflow', 'hidden');*/
}

var emailpage = function() {
	//temploc='http://www.tdshou.com/Email_Page/?myURL=';
	temploc='http://www.tdshou.com/Email_Page/?myURL=';
	temploc = temploc + window.location.href.replace(/\&/, '%26').replace(/\?/, '%3F');
	window.location.href = temploc;
}

/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

// TODO JsDoc

/**
 * Create a cookie with the given key and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String key The key of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given key.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String key The key of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function (key, value, options) {
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        
        value = String(value);
        
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(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;
};

	
jQuery(document).ready(function(){
	jQuery(".thickboxcust").bind("click", function(e){
		e.preventDefault();
		var url = jQuery(this).attr("href");
		tb_show('',url+'?KeepThis=true&amp;TB_iframe=true&amp;height=580&amp;width=570');
	});
							
	jQuery(".thickboxAR").bind("click", function(e){
		e.preventDefault();
		var url = jQuery(this).attr("href");
		tb_show('',url+'?KeepThis=true&amp;TB_iframe=true&amp;height=470&amp;width=670');
	});
	

	
});
