/*################################################################################
##################################################################################
####  Page Scripts                                                            ####
####  Requires: jQuery, sIFR                                                  ##*/

//Initialize the sIFR fonts
var tradeGothicLight        = { src: '/scripts/sifr436/fonts/tradeGothicLight.swf' };
var tradeGothicBold         = { src: '/scripts/sifr436/fonts/tradeGothicBold.swf' };

sIFR.useDomLoaded = false;
sIFR.activate(
	[
		tradeGothicLight,
		tradeGothicBold
	]
);


jQuery("document").ready(
    function($){
        //SIFR FONT REPLACEMENTS
        
        // CONTENT AREA
        sIFR.replace(tradeGothicLight, {
            selector: '#MainContent h1',
            css: '.sIFR-root{ font-size: 22px; color: #15498d; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; }',
            offsetTop: '0',
            tuneHeight: '-7px',
            wmode: 'transparent',
            ratios: [6, 1.58, 7, 1.48, 8, 1.41, 9, 1.35, 11, 1.29, 14, 1.3, 16, 1.26, 20, 1.27, 24, 1.26, 25, 1.24, 26, 1.25, 35, 1.24, 49, 1.23, 74, 1.22, 75, 1.21, 79, 1.22, 80, 1.21, 81, 1.22, 1.21]
        });
        sIFR.replace(tradeGothicLight, {
            selector: '#MainContent h2',
            css: '.sIFR-root{ font-size: 22px; color: #4b4b4d; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; }',
            offsetTop: '0',
            tuneHeight: '-7px',
            wmode: 'transparent',
            ratios: [6, 1.58, 7, 1.48, 8, 1.41, 9, 1.35, 11, 1.29, 14, 1.3, 16, 1.26, 20, 1.27, 24, 1.26, 25, 1.24, 26, 1.25, 35, 1.24, 49, 1.23, 74, 1.22, 75, 1.21, 79, 1.22, 80, 1.21, 81, 1.22, 1.21]
        });
        sIFR.replace(tradeGothicLight, {
            selector: '#Features h1',
            css: '.sIFR-root{ font-size: 22px; color: #15498d; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; }',
            offsetTop: '0',
            tuneHeight: '-7px',
            wmode: 'transparent',
            ratios: [6, 1.58, 7, 1.48, 8, 1.41, 9, 1.35, 11, 1.29, 14, 1.3, 16, 1.26, 20, 1.27, 24, 1.26, 25, 1.24, 26, 1.25, 35, 1.24, 49, 1.23, 74, 1.22, 75, 1.21, 79, 1.22, 80, 1.21, 81, 1.22, 1.21]
        });
        sIFR.replace(tradeGothicLight, {
            selector: '#StandardPage h1',
            css: '.sIFR-root{ font-size: 16px; color: #4b4b4d; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; }',
            offsetTop: '0',
            tuneHeight: '-5px',
            wmode: 'transparent',
            ratios: [6, 1.58, 7, 1.48, 8, 1.41, 9, 1.35, 11, 1.29, 14, 1.3, 16, 1.26, 20, 1.27, 24, 1.26, 25, 1.24, 26, 1.25, 35, 1.24, 49, 1.23, 74, 1.22, 75, 1.21, 79, 1.22, 80, 1.21, 81, 1.22, 1.21]
        });
        sIFR.replace(tradeGothicBold, {
            selector: '#StandardPage h2',
            css: '.sIFR-root{ font-size: 22px; font-weight: bold; color: #15498d; line-height:26px; margin: 0px 0px 0px 0px; padding: 0px 0px 5px 0px; }',
            offsetTop: '0',
            tuneHeight: '-5px',
            wmode: 'transparent',
            ratios: [6, 1.58, 7, 1.48, 8, 1.41, 9, 1.35, 11, 1.29, 14, 1.3, 16, 1.26, 20, 1.27, 24, 1.26, 25, 1.24, 26, 1.25, 35, 1.24, 49, 1.23, 74, 1.22, 75, 1.21, 79, 1.22, 80, 1.21, 81, 1.22, 1.21]
        });
        
        
        // MEDIA FLASH PLAYER
        var $videoDiv = $('#ContentHeaderVideo');
        if(0 < $videoDiv.length)
        {
        	var pageID = $videoDiv.children('input').val();
        	$videoDiv.children('input').detach();
        	if (pageID){
          	  $.ajax(
        	    {
            		cache: false,
            		data: 'type=page&id=' + pageID,
            		dataType: 'text',
            		success: function(data, status, req)
            		{
            			if(data)
            			{
            				loadPageVideo('ContentHeaderVideo', data);
            			}
            		},
            		type: 'post',
            		url: '/data/video/'
        	    }
        	  );
        	}
        }
        
        // RESOURCE CENTER VIDEO FLASH PLAYER
        var $videoDiv = $('#rc-videos');
        if(0 < $videoDiv.length)
        {
        	var vType = $videoDiv.children('#rc_videotype').val();
        	var vID = $videoDiv.children('#rc_videoid').val();
        	$videoDiv.children('#rc_videotype').detach();
        	$videoDiv.children('#rc_videoid').detach();
        	if (vType && vID){
          	  $.ajax(
          	    {
            		cache: false,
            		data: 'type=rc'+vType+'&id=' + vID,
            		dataType: 'text',
            		success: function(data, status, req)
            		{
            			if(data)
            			{
            				loadPageVideo('rc-videos', data);
            			}
            		},
            		type: 'post',
            		url: '/data/video/'
        	    }
        	  );
        	}
        }
        
        // RESOURCE CENTER PODCAST FLASH PLAYER
        var $audioDiv = $('#rc-audio');
        if(0 < $audioDiv.length)
        {
        	var aID = $audioDiv.children('input').val();
        	$audioDiv.children('input').detach();
        	if (aID){
          	  $.ajax(
        	      {
            	  	cache: false,
            		data: 'id=' + aID,
            		dataType: 'text',
            		success: function(data, status, req)
            		{
            			if(data)
            			{
            				loadPageAudio('rc-audio', data);
            			}
            		},
            		type: 'post',
            		url: '/data/podcast/'
        	      }
        	  );
        	}
        }
        
        var StudiesDetailFirst = $('#Sections ul#section-control li:first-child');
        if (0 < StudiesDetailFirst.length){
          $(StudiesDetailFirst).addClass("Active");
          $('#Sections div.Section:first').addClass("Active");
        }
        
        // CASE STUDIES SLIDESHOW FLASH PLAYER
        var shows = new Array("challenge","solution","result","testimonial");
        var showDiv;
        for(s=0;s<shows.length;s++){
          showDiv = $('#slideshow-'+shows[s]);
          if(0 < showDiv.length){
        	var sID = showDiv.children('input').val();
        	showDiv.children('input').detach();
            loadCaseStudies('slideshow-'+shows[s],'/data/casestudy/'+shows[s]+'?id='+sID);
          }
        }
        
        // SEARCH FORM SCRIPTS
        $('#SearchText').focus(
        	function (e)
        	{
        		var $this = $(this);
        		
        		if('Search' == $this.val())
        		{
        			$this.val('');
        		}
        	}
        ).blur(
        	function (e)
        	{
        		var $this = $(this);
        		
        		if('' == $this.val())
        		{
        			$this.val('Search');
        		}
        	}
        );
    }
);

function loadPageVideo(item, filePath)
{
	var flashvars = {};
	var params = {};
	var attributes = {};
	
	flashvars.videopath = filePath;
	
	params.wmode = 'opaque';
	params.allowscriptaccess = 'always';
	params.allowFullScreen = "true";
	
	attributes.id = item;
	attributes.align = 'center';
	
	swfobject.embedSWF('/flash/video.swf', item, '675', '380', '9.0.0', null, flashvars, params, attributes);
	
	jQuery('#' + item + ' object, #' + item + ' embed').focus();
}

function loadPageAudio(item, filePath)
{
	var flashvars = {};
	var params = {};
	var attributes = {};
	
	flashvars.audiopath = filePath;
	
	params.wmode = 'opaque';
	params.allowscriptaccess = 'always';
	
	attributes.id = item;
	attributes.align = 'center';
	
	swfobject.embedSWF('/flash/podcast.swf', item, '328', '185', '9.0.0', null, flashvars, params, attributes);
	
	jQuery('#' + item + ' object, #' + item + ' embed').focus();
}

function loadCaseStudies(item, filePath)
{
	var flashvars = {};
	var params = {};
	var attributes = {};
	
	flashvars.xmlpath = filePath;
	
	params.wmode = 'opaque';
	params.allowscriptaccess = 'always';
	
	attributes.id = item;
	attributes.align = 'center';
	
	swfobject.embedSWF('/flash/casestudy.swf', item, '386', '260', '9.0.0', null, flashvars, params, attributes);
	
	jQuery('#' + item + ' object, #' + item + ' embed').focus();
}
