/*
 * Revision: e7-Revision 162 $
 */
var draeger;
if (!draeger) {
	draeger = {}
}

if (typeof jQuery != 'undefined') {
    $.extend(draeger, {
    	
    	
    	// Init after page load
    	init: function(){

    		draeger.bindClickToThumb();
    	
    		$("#products").tabs({
    			show: function(event, ui){draeger.refreshTabView(event, ui)}
    		});
    		
    		$('.tabs a').click(function(){
    			var that = this;
    			s.prop1 = "";
    			s.prop2 = "";
    			s.pageName = 'Camp Responder - '+that.rel;
    			s.t();
    		})
    		
    		var imageArray = [];
    		$('.thumbs a.image').each(function(index, item){
    			imageArray.push($(item).attr('rel'));
    		});
    		draeger.imagePreloader(imageArray);
    		
    		if(draeger.ENV == 'responder_microsite'){
    			// local
    			draeger.ROOT = 'http://localhost:8095';
    		} else if(draeger.ENV == 'responder_microsite1' || draeger.ENV == 'responder_microsite2' || draeger.ENV == 'responder_microsite3'){
    			// Stage 1, 2 or 3
    			draeger.ROOT = 'http://draeger.ham.e-7.com';
    		} else {
    			draeger.ROOT = 'http://campaigns.draeger.com';
    		}


    	},
    	
    	refreshTabView: function(event, ui) {

    		//$('.thumbs a.image').trigger('click');
    		$('.thumbs a').removeClass('activeThumb');
    		$('.thumbs a.image').trigger('click');
    		$('.thumbs a.image').addClass('activeThumb');
    		
    	},
    	
    	bindClickToThumb: function(){
    		$('.thumbs a').live('click', function(event){
    			var that = this;
    			var tabID = $(that).attr('lang');
    			draeger.showMediaItem(that, tabID);
    			$('.thumbs a').removeClass('activeThumb');
    			$(that).addClass('activeThumb');
    		});
    		
    		
    		
    		
    		
    	},
    	
    	showMediaItem: function(elem, tab) {
    		var mediaCategory = $(elem).attr('class');
    		// method "show" depends on category
    		if(mediaCategory == 'image'){
    			draeger.showImage($(elem).attr('rel'), $(elem).attr('alt'), tab);
    			 s.prop1 = $(elem).attr('name')+":Bild";
    			 s.prop2 = "";
    		}
    		if(mediaCategory == 'video'){
    			draeger.showVideo($(elem).attr('rel'), tab);
    			s.prop1 = $(elem).attr('name')+":Video";
    			var filmString = $(elem).attr('name');
    			var filmArray = filmString.split(':');
   		     	s.prop2 = "Produktfilm:"+filmArray[1];
    		}
    		if(mediaCategory == 'system'){
    			draeger.showSystem($(elem).attr('rel'), tab);
    			s.prop1 = $(elem).attr('name')+":Systemlösung";
    			s.prop2 = "";
    		}
    		if(mediaCategory == 'degree360'){
    			draeger.showDegree($(elem).attr('rel'), tab);
    			s.prop1 = $(elem).attr('name')+":360Grad";
    			s.prop2 = "";
    		}
    		s.linkTrackVars = 'prop1,prop2';
    		s.tl(true,'o', 'Camp Responder');
    	},
    	
    	showImage: function(url, alt, tab){
    		var image = $('<img/>');
    		
    		image.attr({
    			'src': url,
    			'alt': alt
    		});
    		$('#'+tab+' .media-area').html(image);
    	},
    	
    	showDegree: function(url, tab){
    		$('#'+tab+' .media-area').flash({
                allowScriptAccess:"always",
                allowfullscreen: true,
                src: url,
                width: 545,
                height: 470,
                base: ".",
                quality: "high",
                flashvars: {
                    autoPlay : "true",
                    playIcon : "#ffffff",
                    controlsBg : "#616469",
                    controlsBgAlpha : '1.0'
                }
                },
                { version: "9.0.115.0" },
                // Insert Flash Function
                function(htmlOptions) {
                    $(this)[0].innerHTML=$.fn.flash.transform(htmlOptions);
                },
                // Noflash Alternative
                function(htmlOptions) {

                }

            );

    	},
    	
    	showVideo: function(url, tab){
    		
    		$('#'+tab+' .media-area').flash({
                allowScriptAccess:"always",
                allowfullscreen: true,
                src: "../../assets/films/main.swf",
                width: 545,
                height: 470,
                base: ".",
                quality: "high",
                flashvars: {
                    autoPlay : "true",
                    videoPath : url,
                    playIcon : "#ffffff",
                    controlsBg : "#616469",
                    controlsBgAlpha : '1.0'
                }
                },
                { version: "9.0.115.0" },
                // Insert Flash Function
                function(htmlOptions) {
                    $(this)[0].innerHTML=$.fn.flash.transform(htmlOptions);
                },
                // Noflash Alternative
                function(htmlOptions) {

                }

            );
    		
    		s.tl(true,'o', 'Camp Responder - Video - '+url);

    	},
    	
    	showSystem: function(url, tab){
    		
    		tb_show('', '#TB_inline?height=515&amp;width=944', '');
    		
    		// Wait for thickbox
    		window.setTimeout(function(){
    			var systemIntro = "true" ;
        	    $('#TB_ajaxContent').flash({
        	        allowScriptAccess:"always",
        	        allowfullscreen: true,
        	        src: "../../assets/system/main.swf",
        	        width: 944,
        	        height: 510,
        	        quality: "high",
        	        flashvars: { 
        	    		xmlPath: '../../assets/system/xml/'+url,
        	    		stylePath: '../../assets/system/css/style.swf',
        	    		showIntro: systemIntro
        	    		}
        	        },
        	        { version: "9.0.115.0" },
        	        // Insert Flash Function
        	        function(htmlOptions) {
        	                $(this)[0].innerHTML=$.fn.flash.transform(htmlOptions);
        	        },
        	        // Noflash Alternative
        	        function(htmlOptions) {

        	    });
    			
    		}, 2000);
    		
    		$('#'+tab+' .thumbs a.image').trigger('click');

    	},
    	
    	imagePreloader: function(urlArray){
    		var image = [];
    		$.each(urlArray, function(index, item){
    			image[index] = new Image();
    			image[index].src = item;
    		});
    		//alert(urlArray);
    	}
    	
    	

    })
    /* page load */
    $(document).ready(function() {
    	draeger.init();
    	draeger.ENV = environment;
    });
}

