// Client.js
var Client=Class.create(ChasteEnvironment,{'initialize':function($super){$super(false,true);fire('client:initialized');}});

// GTGVideoPlayer.js
var GTGVideoPlayer = Class.create(
  lbVideoPlayer, {
    'defaults': {
	  'id'			: 'fdvsdfvsdfvsfdvdf',
	  'skin'		: '/%2B%2Bresource%2B%2Bgtg/swf/gtg_player_skin.swf',
	  'volume'		: 100,
	  'height'		: 364,
	  'width'		: 560,
	  'autoplay'	: true,
	  'initialPic'	: false,
	  'videoFile'	: false,
	  'flashFile'	: '/++resource++base/swf/lbVideoPlayer/player.swf',
	  
	  
	  /*******/	  

	  'hoverControls' : false,
	  'finalPic'      : false,
	  'continuousPlay': true,
	  'xmlFile'       : false,
	  'playAdvert'    : false,
	  'clickableAd'   : false,
	  'controlsDisabled' : false,
	  'wmode'         : 'transparent'

	},
	
	'embed'			: function(){
	  
	  if( this.flashvars.videoFile ){
		this.flashvars.videoFile = '/videos/' + this.flashvars.videoFile + '/content_vp6.flv';
	  }
	  
	  if( this.flashvars.initialPic ){
		this.flashvars.initialPic = '/videos/' + this.flashvars.initialPic + '/thumbnail.png';
	  }
      
      if( this.playerVersion.major < 8){
          $$('.fallback')[0].setStyle({display : 'block'});
      }else
        swfobject.embedSWF(this.options.flashFile, this.div_id, this.options.width, this.options.height, "8","expressInstall.swf", this.flashvars, this.params, this.attributes);

	}
  }
);

function gtg_get_screen_width(){
  return screen.width;
}

var avantGLTBook = {
	src: '/++resource++gtg/swf/avantGardeGothicMedium.swf'
  ,ratios : [8, 1.43, 11, 1.38, 13, 1.33, 20, 1.32, 21, 1.28, 24, 1.3, 25, 1.28, 29, 1.29, 34, 1.28, 37, 1.27, 41, 1.28, 47, 1.27, 72, 1.26, 75, 1.25, 76, 1.26, 79, 1.25, 80, 1.26, 83, 1.25, 84, 1.26, 87, 1.25, 88, 1.26, 1.25]
};

var avantNav = {
  src: '/++resource++gtg/swf/avantGardeGothicDemi.swf'
  ,ratios : [7, 1.47, 10, 1.43, 11, 1.36, 14, 1.38, 18, 1.36, 22, 1.34, 25, 1.32, 28, 1.33, 29, 1.31, 32, 1.32, 33, 1.3, 37, 1.31, 52, 1.3, 55, 1.29, 59, 1.3, 86, 1.29, 88, 1.28, 89, 1.29, 90, 1.28, 94, 1.29, 95, 1.28, 96, 1.29, 102, 1.28, 103, 1.29, 1.28]
}

var avantSubnav = {
  src: '/++resource++gtg/swf/avantGardeGothicBook.swf'
	,ratios: [6, 1.41, 9, 1.35, 15, 1.29, 21, 1.25, 22, 1.22, 27, 1.24, 29, 1.21, 34, 1.22, 41, 1.21, 45, 1.2, 46, 1.21, 50, 1.2, 51, 1.21, 64, 1.2, 68, 1.19, 69, 1.2, 73, 1.19, 74, 1.2, 123, 1.19, 124, 1.18, 1.19]
}

// SIFRController.js
var SIFRController = Class.create({
        'sizeOnOnload': false,
        'initialize': function ($target, $node_name) {
            var target = $($target);
            if (target) {
                var h4_titles = target.select($node_name);
                if (h4_titles.length > 0 ) {
                    this.load_titles();
                    var checker = this.checkTextSize.bind(this);
                    this.pe = new PeriodicalExecuter(checker, 0.5);
                    this.checkTextSize();
                }
            }
        },
        'load_titles': function () {
			sIFR.replace(
                avantGLTBook, {
                    selector: 'h1.carbon-title',
                    css: [
						'.sIFR-root { text-align: left; color: #F37B21; font-size: 28px; leading : -5; letter-spacing: -0.6;  }',
						'sub { font-size : 40px; }'
                    ]
                }
            );

            sIFR.replace(
                avantGLTBook, {
                    selector: 'h1.podcasts-title',
                    css: [
                        '.sIFR-root { text-align: left; color: #E10E78; font-size: 28px; leading : -5; letter-spacing: -0.6;  }',
                    ],
                    offsetTop : 5
                }
            );

            sIFR.replace(
                avantGLTBook, {
                    selector: 'h1.contact-title',
                    css: [
                        '.sIFR-root { text-align: left; color: #9A4D9E; font-size: 28px; leading : -5; letter-spacing: -0.6;  }',
                    ]
                }
            );

            sIFR.replace(
                avantGLTBook, {
                    selector: 'h1.news-title',
                    css: [
                        '.sIFR-root { text-align: left; color: #24ade3; font-size: 28px; leading : -5; letter-spacing: -0.6;  }',
                    ]
                }
            );


			sIFR.replace(
                avantGLTBook, {
                    selector: 'h1.norm-title',
                    css: [
                        '.sIFR-root { text-align: left; color: #8CC63F; font-size: 28px; leading : -5; letter-spacing: -0.6;  }',
                    ]
                }
            );

			sIFR.replace(
                avantGLTBook, {
                    selector: '.gtg-title h2',
                    css: [
                        '.sIFR-root { text-align: left; color: #ffffff; font-size: 18px; leading : -2 }'
                    ]
                }
            );

			/*
			 *	Mainnav top
			 **/
			sIFR.replace(
                avantNav, {
                    selector: '#mainNav li',
                    css: [
                        '.sIFR-root { text-align: center; color: #87746A; font-size: 14px; }',
                        'a { text-decoration : none; color : #87746A}',
						'.selected { color : #ffffff }',
						'a:hover{ text-decoration : none; color : #ffffff}'
                    ],
					offsetTop : 2,
					tagAfter : "a",
					onRollOver : function(arg){
						arg.changeCSS('a { color : #ffffff; text-align: center; text-decoration: none; } a:hover{ color : #ffffff}');
						if( Prototype.Browser.IE ){
							$(this.id).parentNode.parentNode.style.backgroundPosition = '0px -52px';
							$(this.id).parentNode.style.backgroundPosition = '100% -52px';
						}	
					},
					onRollOut : function(arg){
						arg.changeCSS(
									'a { text-decoration : none; color : #87746A; text-align: center;} \
									.selected { color : #ffffff } \
									a:hover{ text-decoration : none; color : #ffffff}');
						if( Prototype.Browser.IE ){
							$(this.id).parentNode.parentNode.style.backgroundPosition = '0px 0px';
							$(this.id).parentNode.style.backgroundPosition = '100% 0px';
						}
					}
                }
            );
			
			sIFR.replace(
                avantGLTBook, {
                    selector: 'ul.news-lhs li.active',
                    css: [
                        '.sIFR-root { text-align: left; color: #24ade3; font-size: 12px; }',
                        'a { text-decoration : none; color : #24ade3}',
						'a:hover{ text-decoration : none; color : #24ade3}'
                    ],
					offsetTop : 3
                }
            );
			
			sIFR.replace(
                avantGLTBook, {
                    selector: 'ul.news-lhs li',
                    css: [
                        '.sIFR-root { text-align: left; color: #87746A; font-size: 12px; }',
                        'a { text-decoration : none; color : #87746A}',
						'a:hover{ text-decoration : none; color : #24ade3}'
                    ],
					offsetTop : 3
                }
            );

			sIFR.replace(
                avantGLTBook, {
                    selector: 'ul.carbon-lhs li.active',
                    css: [
                        '.sIFR-root { text-align: left; color: #F37B21; font-size: 12px; }',
                        'a { text-decoration : none; color : #F37B21}',
						'a:hover{ text-decoration : none; color : #F37B21}',
						'sub { font-size : 60px; }'
                    ],
					offsetTop : 3
                }
            );
			
			sIFR.replace(
                avantGLTBook, {
                    selector: 'ul.carbon-lhs li',
                    css: [
                        '.sIFR-root { text-align: left; color: #87746A; font-size: 12px; }',
                        'a { text-decoration : none; color : #87746A}',
						'a:hover{ text-decoration : none; color : #F37B21}',
						'sub { font-size : 60px; }'
                    ],
					offsetTop : 3
                }
            );

			sIFR.replace(
                avantGLTBook, {
                    selector: 'ul.lhs li.active',
                    css: [
                        '.sIFR-root { text-align: left; color: #87746A; font-size: 12px; }',
                        'a { text-decoration : none; color : #8CC63F}',
						'a:hover{ text-decoration : none; color : #8CC63F}'
                    ],
					offsetTop : 3
                }
            );
			
			sIFR.replace(
                avantGLTBook, {
                    selector: 'ul.lhs li',
                    css: [
                        '.sIFR-root { text-align: left; color: #87746A; font-size: 12px; }',
                        'a { text-decoration : none; color : #87746A}',
						'a:hover{ text-decoration : none; color : #8CC63F}'
                    ],
					offsetTop : 3
                }
            );
			
			// if we sIFR the subnav in about us then we don't need it to have padding
			$$('ul.lhs li').each(function(element){
										element.setStyle({padding: '0px'});
									});

		
			/*
			 *	Subnav top
			 **/

			sIFR.replace(
                avantSubnav, {
                    selector: 'div#subnav div.norm div',
                    css: [
                        '.sIFR-root { text-align: center; color: #87746A; font-size: 12px; }',
                        'a { text-decoration : none; color : #87746A}',
						'.active {color : #8CC63F}',
						'a:hover{ text-decoration : none; color : #8CC63F}'
                    ],
					forceSingleLine: true
                }
            );
			
			sIFR.replace(
                avantSubnav, {
                    selector: 'div#subnav div.news-item div',
                    css: [
                        '.sIFR-root { text-align: center; color: #87746A; font-size: 12px; }',
                        'a { text-decoration : none; color : #87746A}',
						'.active-news{color : #27ACE3}',
						'a:hover{ text-decoration : none; color : #27ACE3}'
                    ],
					forceSingleLine: true,
					onReplacement : function (){
						$$('div#subnav div.first-item').each(function(element){
													element.setStyle({paddingLeft: '0px'});
						});
					}
                }
            );
			
			sIFR.replace(
                avantSubnav, {
                    selector: 'div#subnav div.carbon-item div',
                    css: [
                        '.sIFR-root { text-align: center; color: #87746A; font-size: 12px; }',
                        'a { text-decoration : none; color : #87746A}',
						'.active-low-carbon {color : #F37B21}',
						'a:hover{ text-decoration : none; color : #F37B21}'
                    ],
					forceSingleLine: true
                }
            );
			
			sIFR.replace(
                avantSubnav, {
                    selector: 'div#subnav div.podcast-item div',
                    css: [
                        '.sIFR-root { text-align: center; color: #87746A; font-size: 12px; }',
                        'a { text-decoration : none; color : #87746A}',
						'.active-podcasts {color : #E10E78}',
						'a:hover{ text-decoration : none; color : #E10E78}'
                    ],
					forceSingleLine: true,
					onReplacement : function(){
						/* if we sIFR the subnav then we need it to have padding
						$$('div#subnav div.ml').each(function(element){
													element.setStyle({paddingLeft: '5px'});
						});
						*/
					}
                }
            );
			
			sIFR.replace(
                avantSubnav, {
                    selector: 'div#subnav div.contact-item div',
                    css: [
                        '.sIFR-root { text-align: center; color: #87746A; font-size: 12px; }',
                        'a { text-decoration : none; color : #87746A}',
						'.active-contact {color : #9A4D9E}',
						'a:hover{ text-decoration : none; color : #9A4D9E}'
                    ],
					forceSingleLine: true
                }
            );
			
			sIFR.replace(
                avantGLTBook, {
                    selector: '#threeColWrap h6',
                    css: [
                        '.sIFR-root { text-align: left; color: #87746A; font-size: 18px; leading : -2 }'
                    ],
					offsetTop : 3
                }
            );

        },
        'checkTextSize': function (){
            var checker = $('textSizeChecker');
            if(!checker){
                // create the layer to check if the text has been resized
                var sizer_reference = document.createElement('div');
                    sizer_reference.id = 'textSizeChecker';
                    sizer_reference.style.fontSize    = '1em';
                    sizer_reference.style.height    = 'auto';
                    sizer_reference.style.position    = 'absolute';
                    sizer_reference.style.left        = '-999px';
                    sizer_reference.innerHTML = 'super';
                document.body.appendChild(sizer_reference);
                sizer_reference = null;
                checker = $('textSizeChecker');
            }
            if (this.sizeOnOnload) {
                /*if( BrowserDetect.browser == 'Firefox' && BrowserDetect.version > 2){
                    var resi = ($('ff3_div_2').offsetX / $('ff3_div_1').offsetX) + 1;

                }*/
                if (this.sizeOnOnload != checker.offsetHeight){
                    var flash_txt = $$('.sIFR-replaced');
                    var txt_flash = $$('.sIFR-alternate');

                    for( var i = 0; i < flash_txt.length; i++){

                        var tag_name    = flash_txt[i].tagName;
                        var parente        = flash_txt[i].parentNode;

                        var redo_title        = document.createElement(tag_name);
                        redo_title.innerHTML= txt_flash[i].innerHTML;
                        parente.insertBefore(redo_title, flash_txt[i]);
                        parente.removeChild(flash_txt[i]);

                    }
                    flash_txt = txt_flash = redo_title = tag_name = parente = null;
                    this.load_titles();
                }
            }
            this.sizeOnOnload = checker.offsetHeight;
        }
    }
);

// init.js
observe('dom:loaded',function(){var debug=false;if(window.location.href.indexOf(':8080')>-1){debug=true;}
Logger.addMethods({'DEBUG':debug});var client=new Client();});

// Client.js
var Client = Class.create(
  ChasteEnvironment, {
    'initialize': function ($super) {
      $super(false, true);
      fire('client:initialized');
//	  var sifr_controller = new SIFRController('basis', 'h1');
	  
	  if( $('submit_btn') && Prototype.Browser.IE){
		$('submit_btn').observe('mouseover', function(){ this.setStyle({backgroundPosition : '0 100%'}) });
		$('submit_btn').observe('mouseout', function(){ this.setStyle({backgroundPosition : '0 0'}) });
	  }
    }
  }
);


