
	/*
	 * CONFIG STUFF UP HERE	  
	 */

	var _branchSpecificConfig = {
		'leavingWebsiteMessages': {
			'_default': {
				'msg1': 'You are leaving this UCB website and are about to enter the website of a third party. UCB is not responsible for and does not endorse the content of the website you are about to enter.',
				'msg2': 'You are leaving this UCB website and are about to enter the website of a third party. UCB is not responsible for and does not endorse the content of the website you are about to enter.'
			},
			'cimzia_nl': {
				'msg1': 'U verlaat nu de site van UCB Pharma B.V. Links naar andere sites worden de bezoekers aangeboden ter informatie. UCB Pharma wijst echter alle verantwoordelijkheid voor de inhoud van deze sites af.',
				'msg2': 'U verlaat nu de site van UCB Pharma B.V. Links naar andere sites worden de bezoekers aangeboden ter informatie. UCB Pharma wijst echter alle verantwoordelijkheid voor de inhoud van deze sites af.'
			},
			'epi_konnect_de': {
				'msg1': 'U verlaat nu de site van UCB Pharma B.V. Links naar andere sites worden de bezoekers aangeboden ter informatie. UCB Pharma wijst echter alle verantwoordelijkheid voor de inhoud van deze sites af.',
				'msg2': 'U verlaat nu de site van UCB Pharma B.V. Links naar andere sites worden de bezoekers aangeboden ter informatie. UCB Pharma wijst echter alle verantwoordelijkheid voor de inhoud van deze sites af.'
			},
			'lme_nl': {
				'msg1': 'U verlaat de website. UCB is niet aansprakelijk voor de inhoud van deze site en onze disclaimer is niet van toepassing. Klik op CANCEL om terug te keren naar onze website.',
				'msg2': 'U verlaat de website. UCB is niet aansprakelijk voor de inhoud van deze site en onze disclaimer is niet van toepassing. Klik op CANCEL om terug te keren naar onze website.'
			},
			'neupro_eu': {
				'msg1': 'You are leaving the Neupro website and are about to enter the website of a third party. UCB is not responsible for and does not endorse the content of the website you are about to enter.',
				'msg2': 'You are leaving the Neupro website and are about to enter the website of a third party. UCB is not responsible for and does not endorse the content of the website you are about to enter.'
			},
			'neupro_gr': {
				'msg1': 'You are leaving the Neupro website and are about to enter the website of a third party. UCB is not responsible for and does not endorse the content of the website you are about to enter.',
				'msg2': 'You are leaving the Neupro website and are about to enter the website of a third party. UCB is not responsible for and does not endorse the content of the website you are about to enter.'
			},
			'pv_eu': {
				'msg1': 'You are about to leave a UCB site to go to a site that, unless identified as such, is not the responsibility of UCB. UCB does not endorse, warrant or guarantee the products, services or information offered or described at this external internet sites, nor does it accept liability arising out of any allegation that such content infringes the intellectual property rights of any person or any liability arising out of any opinion or information contained on such external websites.',
				'msg2': 'You are about to leave a UCB site to go to a site that, unless identified as such, is not the responsibility of UCB. UCB does not endorse, warrant or guarantee the products, services or information offered or described at this external internet sites, nor does it accept liability arising out of any allegation that such content infringes the intellectual property rights of any person or any liability arising out of any opinion or information contained on such external websites.'
			},
			'pv_eu_de': {
				'msg1': 'You are about to leave a UCB site to go to a site that, unless identified as such, is not the responsibility of UCB. UCB does not endorse, warrant or guarantee the products, services or information offered or described at this external internet sites, nor does it accept liability arising out of any allegation that such content infringes the intellectual property rights of any person or any liability arising out of any opinion or information contained on such external websites.',
				'msg2': 'You are about to leave a UCB site to go to a site that, unless identified as such, is not the responsibility of UCB. UCB does not endorse, warrant or guarantee the products, services or information offered or described at this external internet sites, nor does it accept liability arising out of any allegation that such content infringes the intellectual property rights of any person or any liability arising out of any opinion or information contained on such external websites.'
			}
		},
		'videoScrollComponentColorsAndFonts': {
			'_default': {
				'font': typeof(dinReg) == 'undefined' ? {} : dinReg,
				'color': '#f37124',
				'ratios': [8,1.42,9,1.33,12,1.35,15,1.3,19,1.28,27,1.27,28,1.25,32,1.26,33,1.24,34,1.25,48,1.24,52,1.23,53,1.24,73,1.23,76,1.22,77,1.23,81,1.22,82,1.23,1.22]
			},
			'epilepsie_im_griff_de': {
				'font': typeof(dinReg) == 'undefined' ? {} : dinReg,
				'color': '#f37124',
				'ratios': [8,1.42,9,1.33,12,1.35,15,1.3,19,1.28,27,1.27,28,1.25,32,1.26,33,1.24,34,1.25,48,1.24,52,1.23,53,1.24,73,1.23,76,1.22,77,1.23,81,1.22,82,1.23,1.22]
			},
			'epi_konnect_de': {
				'font': typeof(botonmed) == 'undefined' ? {} : botonmed,
				'color': '#c4262e',
				'ratios': [8,1.42,9,1.33,12,1.35,15,1.3,19,1.28,27,1.27,28,1.25,32,1.26,33,1.24,34,1.25,48,1.24,52,1.23,53,1.24,73,1.23,76,1.22,77,1.23,81,1.22,82,1.23,1.22]
			},
			'neupro_eu': {
				'font': typeof(gillsans) == 'undefined' ? {} : gillsans,
				'color': '#005295',
				'ratios': [7, 1.32, 11, 1.31, 13, 1.24, 14, 1.25, 19, 1.23, 27, 1.2, 34, 1.19, 43, 1.18, 47, 1.17, 48, 1.18, 73, 1.17, 74, 1.16, 75, 1.17, 80, 1.16, 81, 1.17, 1.16]
			},
			'neupro_gr': {
				'font': typeof(gillsans) == 'undefined' ? {} : gillsans,
				'color': '#005295',
				'ratios': [7, 1.32, 11, 1.31, 13, 1.24, 14, 1.25, 19, 1.23, 27, 1.2, 34, 1.19, 43, 1.18, 47, 1.17, 48, 1.18, 73, 1.17, 74, 1.16, 75, 1.17, 80, 1.16, 81, 1.17, 1.16]
			},
			'pv_eu': {
				'font': typeof(dinReg) == 'undefined' ? {} : dinReg,
				'color': '#000000',
				'ratios': [8,1.42,9,1.33,12,1.35,15,1.3,19,1.28,27,1.27,28,1.25,32,1.26,33,1.24,34,1.25,48,1.24,52,1.23,53,1.24,73,1.23,76,1.22,77,1.23,81,1.22,82,1.23,1.22]
			},
			'pv_eu_de': {
				'font': typeof(dinReg) == 'undefined' ? {} : dinReg,
				'color': '#000000',
				'ratios': [8,1.42,9,1.33,12,1.35,15,1.3,19,1.28,27,1.27,28,1.25,32,1.26,33,1.24,34,1.25,48,1.24,52,1.23,53,1.24,73,1.23,76,1.22,77,1.23,81,1.22,82,1.23,1.22]
			}
		}
	};
	
	var _baseHref = '';
	
	// CONFIG END, LET'S PARTY

	$(document).ready(function() {
		
		// checking for existing global javascript variable _branchcode
		Branchcode.init();
		
		// init language selectbox
		LanguageSelection.init();
		
		// html5 video start
        $('head').append('<script src="static/js/jwplayer.js" type="text/javascript"></script>');
        $('head').append('<script src="static/js/replaceVideoPlaceholder.js" type="text/javascript"></script>');
        // html5 video end
        
        if (location.hostname.indexOf('krankikom') == -1) {
        	// video scroll component start
            $('head').append('<script src="static/js/jquery.tools.min.js" type="text/javascript"></script>');
            VideoScrollComponent.init();
            // video scroll component end
        }
		
		var linkCollection = $('a');
		taglinks(linkCollection);
		
	});
	
	// throws alert window if global _branchcode is not set!
	var Branchcode = {
		init: function() {
			if (typeof(_branchcode) == 'undefined') {
				alert("To avoid this message please insert following codesnippet to main.cbx just before the first .js file is included (usually library.js):\n\n<script type=\"text/javascript\">\n\tvar _branchcode = '<?=$page['branchCode']?>';\n</script>");
			}
		}
	}
	
	var VideoScrollComponent = {
		player: false,
		api: $('.video-scroll-component .scroll-area .scrollable').data("scrollable"),
		nrPages: Math.ceil($('.video-scroll-component .package').length / 4),
		
		init: function() {
			$('.video-scroll-component .scroll-area .scrollable').scrollable();
			$('.video-scroll-component .package').bind('click', this.itemClicked);
			$('.video-scroll-component .pages span').bind('click', this.paging);
			
			VideoScrollComponent.player = document.getElementById('video-scroll-component-player');

			if (this.api !== undefined) {			
				this.api.onSeek(function() {
					var curPage = this.getIndex() + 1;
					$('.video-scroll-component .pages span').removeClass('active');
					$('.video-scroll-component .pages span.p'+curPage).addClass('active');
				});
				
				this.api.seekTo(0);
			}
			for (var i = 1; i <= this.nrPages; i++) { $('.video-scroll-component .pages').append('<span class="p'+i+'">'+i+'</span> '); }
		},
		itemClicked: function(e) {
			var currentSelection = $(this).attr('rel');
			var currentFolder = $(this).attr('name');

			$('.video-scroll-component .text-area span').addClass('hidden');
			$('.video-scroll-component .text-area span' + '.' + currentSelection).removeClass('hidden');
			
			var color = _branchSpecificConfig['videoScrollComponentColorsAndFonts']['_default']['color'];
			var font = _branchSpecificConfig['videoScrollComponentColorsAndFonts']['_default']['font'];
			var ratios = _branchSpecificConfig['videoScrollComponentColorsAndFonts']['_default']['ratios'];
			
			if (typeof(_branchSpecificConfig['videoScrollComponentColorsAndFonts'][_branchcode]) != 'undefined') {
				color = _branchSpecificConfig['videoScrollComponentColorsAndFonts'][_branchcode]['color'];
				font = _branchSpecificConfig['videoScrollComponentColorsAndFonts'][_branchcode]['font'];
				ratios = _branchSpecificConfig['videoScrollComponentColorsAndFonts'][_branchcode]['ratios']
			}
			
			console.log(font, color, ratios);
			
			sIFR.replace(font, {
			  selector: '.video-scroll-component h2'
			  ,css: '.sIFR-root { color: ' + color + '; }'
				,wmode: 'transparent'
				,ratios:  ratios
			});					
			
			var vidFile = '/_up/' + _branchcode + '/videos/' + currentFolder + '/' + currentSelection + '.flv';
			VideoScrollComponent.player.sendEvent('STOP');
			VideoScrollComponent.player.sendEvent('LOAD', vidFile);
			VideoScrollComponent.player.sendEvent('PLAY');
		},
		paging: function(e) {
			var movTo = $(this).text() - 1;
			this.api.seekTo(movTo);
		}
	}
	
	var LanguageSelection = {
		init: function() {
			if ($("div.language-select").length > 0) {
				$("div.language-select span.arrow").mouseover(function(){
					$(this).addClass('hover');
					$("div.language-select ul").show();
				}).mouseout(function(){
					$(this).removeClass('hover');			
				});		
				
				$("div.language-select ul").mouseout(function( evt ){
					$("div.language-select ul").hide();
				});
				$("div.language-select ul li").mouseover(function(){
					$("div.language-select ul").show();
				});
			}
		}
	}

    function taglinks(linkCollection) {
		
		var msg1 = _branchSpecificConfig['leavingWebsiteMessages']['_default']['msg1'];
		var msg2 = _branchSpecificConfig['leavingWebsiteMessages']['_default']['msg2'];
		
		if (typeof(_branchSpecificConfig['leavingWebsiteMessages'][_branchcode]) != 'undefined') {
			msg1 = _branchSpecificConfig['leavingWebsiteMessages'][_branchcode]['msg1'];
		}
		if (typeof(_branchSpecificConfig['leavingWebsiteMessages'][_branchcode]) != 'undefined') {
			msg2 = _branchSpecificConfig['leavingWebsiteMessages'][_branchcode]['msg2'];
		}
		
		$(linkCollection).each(function(i) {
			var msg = false;
			var tgt = false;
			var track = false;
			var trackURL = false;
			// set message by disclaimer-type
			if ($(this).hasClass('disclaimer-1')) {
				msg = msg1;
			} else if ($(this).hasClass('disclaimer-2')) {
				msg = msg2;
			}
			// track link?
			if (
			    $(this).attr('href') != undefined &&
			    ($(this).attr('href').substr(0, 4) == 'http' || $(this).attr('href').slice(0, 7) == '../_up/' || $(this).attr('href').slice(0, 13) == '/website/_up/')
			) {
			    track = true;
			}
			// has target?
			if ($(this).attr('target')) {
			    tgt = $(this).attr('target') == '_blank' ? '_blank' : false;
			}
			if (!msg && !track) return true;
			if (track) {
			    trackURL = $(this).attr('href').replace('http://www.', '');
			    trackURL = trackURL.replace('https://www.', '');
			    trackURL = trackURL.replace('http://', '');
			    trackURL = trackURL.replace('https://', '');
			    trackURL = trackURL.replace('../_up/', '');
			    trackURL = trackURL.replace('/website/_up/', '');
			    // special treatment for epilepsyadvocate.com
			    trackURL = trackURL.replace('epilepsyadvocate.com/community/join.aspx', 'EA.com/join.aspx');
			    trackURL = trackURL.replace('epilepsyadvocate.com', 'EA.com');
			}
			if (!msg && track) {
			    $(this).bind('click', function() {
			        pageTracker._trackPageview('/' + trackURL);
			    });
			    return true;
			}
			$(this).bind('click', function() {
			    var tmp = confirm(msg);
				if (tmp) {
				    if (track) {
				        pageTracker._trackPageview('/' + trackURL);
				    }
				    if (tgt) {
				        window.open($(this).attr('href'), tgt);
				    } else {
					    location.href = $(this).attr('href');
					}
				}
				return false;
			});
		});
	}
	
	function quickSelectBlock(list) {
	  
		// In case of MSIE, read the <BASE HREF=''/> attribute from the DOM
		// This has to be done because MSIE ingnores the base href when doing a redirect via location.href 
		if (jQuery.browser.msie) 
			base_href = $('base').attr('href');
		else 
			base_href = '';
		if(list.options[list.selectedIndex].value == '' || list.options[list.selectedIndex].value == 0){
			  return false;
		}
		else if (list.options[list.selectedIndex].value) {	    	
	        location.href = base_href+list.options[list.selectedIndex].value;
	    }
	    return false;
	}	
	
	
	// swap component helper functions START
	function toggle(id){
		//if ($('#content'+id).css('display') == 'none'){
		if ($('#show'+id).css('display') == 'inline'){
			showSwapComponent(id);
		} else {
			hideSwapComponent(id);
		}
	}
		
	function hideSwapComponent(id){
		$('#show'+id).css('display','inline');
		$('#content'+id).css('display','none');
	}
	function showSwapComponent(id){
		$('#show'+id).css('display','none');
		$('#content'+id).css('display', 'block');
	}
	function showAllSwapComponentContents(){
		$(".accordion_readmore hideReadMore").css("display","inline");
		$(".hideContent").css("display","block");
	}
	/*
	function hideAllSwapComponentContents(){
		$(".hideContent").css("display","none");
	}
	$(document).ready(function() {
		hideAllSwapComponentContents();
	});
	*/
	// swap component helper functions END
