
var toggled = [];

var stoked = {
	
	browser: $.browser,

	pngfix:function(){
		$('.pngfix').each(function(){
			var bg = $(this).css('background-image');
			if(bg.indexOf(".png")!=-1){
				var bgSrc = bg.split('url("')[1].split('")')[0];
				$(this).css('background-image', 'none');
				$(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+bgSrc+"',sizingMethod='scale')";
			}
		});
	},
	
	quotefix:function(){
		if(this.browser.msie && this.browser.version<8){
			$('q').each(function(){
				$(this).html('<var>&quot;</var>'+$(this).html()+'<var>&quot;</var>');
			});
		}
	},
	
	footerfix:function(){
		if(this.browser.msie && this.browser.version<7){
			var scrollLoc = $('#footer').offset().top;
			$(window).scroll(function () {
				$('#footer').css({top:($(document).scrollTop()+scrollLoc+'px')});
			});
		}
	},
	
	carouselOver:function(elemIndex){
		var bgColor='#fff';
		switch(elemIndex){	/*	all colors should be in regions.css instead	*/
			case 'europa': bgColor='#4380bd'; break;
			case 'afrika': bgColor='#e0b74e'; break;
			case 'indischer-ozean': bgColor='#cc722a'; break;
			case 'ost-asien': bgColor='#7b7c1f'; break;
			case 'australien': bgColor='#e95d0f'; break;
			case 'pazifikinseln': bgColor='#00437d'; break;
			case 'nordamerika': bgColor='#c51d26'; break;
			case 'mittelamerika-karibik': bgColor='#c8d100'; break;
			case 'suedamerika': bgColor='#307629'; break;
		}
		
		$('#carousel_item_'+elemIndex).css({'background-color':'#fff'});
		$('#carousel_label_'+elemIndex).css({'background-color':bgColor});
	},
	carouselOut:function(elemIndex){
		$('#carousel_item_'+elemIndex).css({'background-color':'transparent'});
		$('#carousel_label_'+elemIndex).css({'background-color':'transparent'});
	},
	
	markRegion:function(elemId){
		$('#tooltip_'+elemId+', #tooltip_'+elemId+'_1, #tooltip_'+elemId+'_2, #tooltip_'+elemId+'_3').show();
		$('#region_marker_'+elemId+', #region_marker_'+elemId+'_1, #region_marker_'+elemId+'_2, #region_marker_'+elemId+'_3').addClass('hover');
		$('ul.navi li.'+elemId).addClass('active');
	},
	unmarkRegion:function(elemId){
		$('#tooltip_'+elemId+', #tooltip_'+elemId+'_1, #tooltip_'+elemId+'_2, #tooltip_'+elemId+'_3').hide();
		$('#region_marker_'+elemId+', #region_marker_'+elemId+'_1, #region_marker_'+elemId+'_2, #region_marker_'+elemId+'_3').removeClass('hover');
		$('ul.navi li.'+elemId).removeClass('active');
	},
	
	markCountry:function(elemId){
		$('div#worldmap div#'+elemId).addClass('active');
		$('div#worldmap div#'+elemId+'_label').show();
		
		$('li.region.'+elemId+' b a').addClass('black');
		
	},
	unmarkCountry:function(elemId){
		$('div#worldmap div#'+elemId).removeClass('active');
		$('div#worldmap div#'+elemId+'_label').hide();
		
		$('li.region.'+elemId+' b a').removeClass('black');
		
	},
	
	markEuropeanCountry:function(elemId){
		var hover_image = new Image();
		hover_image.src = '_assets/images/wwd/europa/hover_'+elemId+'.gif';
		$('#hover_image').attr('src', hover_image.src);
		$('#hover_image').css({'display':'block'});
		$('#tooltip_'+elemId).show();
		$('li.'+elemId).addClass('active');
	},
	unmarkEuropeanCountry:function(elemId){
		$('#hover_image').css({'display':'none'});
		$('#tooltip_'+elemId).hide();
		$('li.'+elemId).removeClass('active');
	},
	
	mycarousel_segment:1,
	mycarousel:function(){
		$('#mycarousel').jcarousel({
	        scroll: 3,
	        initCallback: this.mycarousel_initCallback,
	        buttonNextHTML: null,
	        buttonPrevHTML: null
	    });
	},
	
	mycarousel_initCallback:function(carousel){
		$('#mycarousel-next').bind('click', function() {
			if(stoked.mycarousel_segment<4)
				stoked.mycarousel_segment++;
			stoked.mycarousel_checksegment();
			carousel.next();
			return false;
		});
		$('#mycarousel-prev').bind('click', function() {
			if(stoked.mycarousel_segment>1)
				stoked.mycarousel_segment--;
			stoked.mycarousel_checksegment();
			carousel.prev();
			return false;
		});
		stoked.mycarousel_checksegment();
	},
	
	mycarousel_checksegment:function(){
		
		switch(this.mycarousel_segment){
			default:
				$('#mycarousel-prev').css({'background-position':'left 36px','cursor':'pointer'});
				$('#mycarousel-next').css({'background-position':'right -197px','cursor':'pointer'});
				break;
			case 1:
				$('#mycarousel-prev').css({'background-position':'-100px 36px','cursor':'default'});
				break;
			case 4:
				$('#mycarousel-next').css({'background-position':'-100px -197px','cursor':'default'});
				break;
		}
	},
	
	scrolling_menu:function(){
		var scrollLoc = 0;
		if(!(scrollLoc = $('ul.navi li.region li.active').parent().parent().parent().parent().parent('.europa').find('b').offset().top)){
			
			scrollLoc = $('ul.navi li.region li.expanded').parent().parent().find('b').offset().top;
			if(scrollLoc==0){
				scrollLoc = $('ul.navi li.region li.active').parent().parent().find('b').offset().top;
			}
			
			/*if(!(scrollLoc = $('ul.navi li.region li.expanded').parent().parent().find('b').offset().top;)){
				scrollLoc = $('ul.navi li.region li.active').parent().parent().find('b').offset().top;
			}*/
		}
		
	    $('#scrolling_menu').css({top:scrollLoc+'px'});
	    $('#scrolling_menu_indicator').css({top:scrollLoc+10+'px'});
		$(window).scroll(function () {
			$('#scrolling_menu').animate({top:($(document).scrollTop()+scrollLoc+'px')},{duration:500,queue:false});
		});
	},
	
	ticker_break:5000,
	tick_duration:1500,
	ticker_items:null,
	total_ticker:0,
	current_ticker:0,
	tickerval:null,
	
	vticker:function(){
		var ticker_items = new Array();
		$('div.vticker ul.start > li').each(function(i, item){
			ticker_items[i] = $(item).clone();
		});
		this.ticker_items = ticker_items;
		this.total_ticker = this.ticker_items.length;
		if(this.total_ticker>0)
			this.tickerval = window.setInterval('stoked.vticker_tick()', this.ticker_break);
	},
	
	vticker_tick:function(){
		
		elem = $('div.vticker ul.start li:first-child');
		elemHeight = elem.height();
		
		elem.animate({marginTop:-elemHeight}, this.tick_duration, 'swing', function(){
			$(this).remove();
		});
		
		this.ticker_items[this.current_ticker].clone().insertAfter('div.vticker ul.start li:last-child');
		this.current_ticker++;
		if(this.current_ticker==this.total_ticker)
			this.current_ticker = 0;
	},
	
	start_vticker:function(){
		if(this.total_ticker>0)
			this.tickerval = window.setInterval('stoked.vticker_tick()', this.ticker_break);
	},
	stop_vticker:function(){
		window.clearInterval(this.tickerval);
	},
	
	vfader:function(){
		$('div.vfader ul.start').innerfade({
			animationtype: 'fade', // Type of animation 'fade' or 'slide' (Default: 'fade'), 
			speed: 'slow', // Fadingspeed in milliseconds or keywords (slow, normal or fast)(Default: 'normal'), 
			timeout: 8000, // Time between the fades in milliseconds (Default: '2000'), 
			type: 'sequence', // Type of slideshow: 'sequence', 'random' or 'random_start' (Default: 'sequence'), 
			containerheight: '350px' // Height of the containing element in any css-height-value (Default: 'auto')  
		});
	},
	
	lightbox:function(){
		$('ul.samples li a, ul.directions-sketch li a, a.lightframe, div.vfader ul > li > a').lightBox({
			imageLoading:			'_assets/images/lightbox/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
			imageBtnPrev:			'_assets/images/lightbox/lightbox-btn-prev.gif',		// (string) Path and the name of the prev button image
			imageBtnNext:			'_assets/images/lightbox/lightbox-btn-next.gif',		// (string) Path and the name of the next button image
			imageBtnClose:			'_assets/images/lightbox/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
			imageBlank:				'_assets/images/lightbox/lightbox-blank.gif'
		});
	},
	
	iframe_width:0,
	hackedbox:function(loadhref, loadwidth){
		
		this.iframe_width = 900;
		
		try{
			throw document.getElementById('hackedbox-dummyframe');
		}catch(e){
			if(!e){
				this.prepare_iframe(loadhref);
			}else{
				$('#hackedbox-dummyframe').attr('src', loadhref);
			}
		}
		
		this.chackedbox(loadhref, loadwidth);
	},
	chackedbox:function(loadhref, loadwidth){
		if(loadwidth){
			if(loadwidth!=this.iframe_width){
				this.iframe_width = loadwidth;
			}
		}
		
		if($('#lightbox-container-image-box').width()==this.iframe_width+20) {
			this.inject_iframe(loadhref);
		}else {
			window.setTimeout('stoked.hackedbox(\''+loadhref+'\', '+this.iframe_width+')', 500);
		}
	},
	
	prepare_iframe:function(url_to_load){
		$('#body').prepend('<iframe id="hackedbox-dummyframe" src="'+url_to_load+'" border="0" frameborder="0" style="border:solid #fff 0px;position:absolute;width:'+this.iframe_width+'px;height:100%;display:none" ></iframe>');
	},
	inject_iframe:function(){
		
		$('#lightbox-image').remove();
		$('#lightbox-nav').remove();
		
		$('#hackedbox-dummyframe')
			.clone()
			.attr('id', 'hackedbox-lightframe')
			.prependTo('#lightbox-container-image');
			
		$('#hackedbox-lightframe')
			.width($('#lightbox-container-image-box').width()-20)
			.height($('#lightbox-container-image-box').height()-20)
			.show();
		
	},
	
	pause:function(ms) {
		var date = new Date(); 
		curDate = null;
		do{
			var curDate = new Date();
		}
		while(curDate - date < ms);
	},
	
	toggle:function(container_id){
		
		toggled[container_id] = $('#'+container_id).css('display');
		
		if(toggled[container_id]=='block'){
			$('#'+container_id).slideUp('slow');
		}else{
			$('#'+container_id).slideDown('slow');
		}
		
	},
	
	outgoing_links:function(){
		$('a[target=_blank]').each(function(i, item){
			alert($(this).attr('href'));
		});
	}
	
};



