document.observe("dom:loaded", function() {
	if($('bodyid').hasClassName('design1') == false) {
		scroller();
		Event.observe(window, 'scroll', function() {
			scroller();
		});
	}
	set_expander();
});

function set_expander() {
	$$('.expand_content').each(function(el) {
		el.hide();
	});
	$$('.expand_title').each(function(el) {
		el.observe("click", expand);
		el.setStyle({cursor: 'pointer'});
		el.insert({top: "<div class='expand_arrow' style='float:left; width: 24px; height: 31px; background-image:url(/images/tree_arrows.png);'></div>"});
	});
}

function expand(el) {
	c = this.next('.expand_content');

	if(c.visible()) {
		Effect.BlindUp(c);
		this.firstDescendant().setStyle({backgroundPosition: '0px 0px'});
	} else {
		Effect.BlindDown(c);
		this.firstDescendant().setStyle({backgroundPosition: '0px 34px'});
	}
}

function show_footer() {
	new Effect.Opacity('footer', {from: 0.7, to: 1, duration: 0.2});
}

function hide_footer() {
	new Effect.Opacity('footer', {from: 1, to: 0.7, duration: 0.2});
}

menu_action = new Array();
function show_menu(menu_id) {
	var queue = Effect.Queues.get('showmenu');
	queue.each(function(effect) {effect.cancel();});
	dist = 275;
	if(Object.isUndefined(menu_action[menu_id]) || menu_action[menu_id]=='') {
		$(menu_id).style.zIndex=50;
		$(menu_id).morph('margin-top: '+dist+'px;', {
			duration: 0.5,
			transition: Effect.Transitions.Back.easeOut.custom(1),
			queue: {position: 'end', scope: 'showmenu'}
		});
	} else {
		menu_action[menu_id].cancel();
		menu_action[menu_id] = '';
		$(menu_id).morph('margin-top: '+dist+'px;', {
			duration: 0.5,
			transition: Effect.Transitions.Back.easeOut.custom(1),
			queue: {position: 'end', scope: 'showmenu'}
		});
	}
}

function hide_menu(menu_id) {
	$(menu_id).style.zIndex=49;
	menu_action[menu_id] = new Effect.Morph(menu_id, {
		style: 'margin-top: 0px;',
		duration: 0.4,
		delay: 0.2,
		afterFinish: function(){
			menu_action[menu_id]=''
		}
	});
}

/*prev_pos = 0;
function scroller() {
	s = document.viewport.getScrollOffsets().top;
	v = document.viewport.getDimensions().height;
	h = document.documentElement.scrollHeight;
	p = (s)/(h-v)*100;
	new Effect.Tween(null, prev_pos, p, {
		duration:3,
		//fps:30,
		queue: {position: 'end', scope: 'scroller'},
		afterUpdate: function() {
			if (s != document.viewport.getScrollOffsets().top) {
				var queue = Effect.Queues.get('scroller');
				queue.each(function(effect) {effect.cancel();});
				scroller();
			}
		},
		afterFinish:function(){
			prev_pos = p;
			scroller();
		}},
		function(x){
			$('bodyid').setStyle({'backgroundPosition': '50% '+x+'%'});
			prev_pos = x;
		}
		);
}*/

function scroller() {
	s = document.viewport.getScrollOffsets().top;
	v = document.viewport.getDimensions().height;
	h = document.documentElement.scrollHeight;
	p = (s)/(h-v)*100;
	$('bodyid').setStyle({'backgroundPosition': '50% '+p+'%'});
}

/**
 * Panel
 */
function panel(cur, h1, h2) {
	var queue = Effect.Queues.get('panels');
	queue.each(function(effect) {effect.cancel();});
	new Effect.Parallel([
		new Effect.Morph('panel'+cur, {
			sync: true,
			style: 'width:465px;',
			afterFinish: function(){
				//$('panel'+cur).setAttribute('data-width', 465);
				$('panel_info'+cur).appear({duration:0.3});
			}
		}),
		new Effect.Fade('panel_screen'+cur, {sync: true}),
		new Effect.Morph('panel'+h1, {
			sync: true,
			style: 'width:187px;'
		}),
		new Effect.Appear('panel_screen'+h1, {
			sync: true,
			to: 0.5
		}),
		new Effect.Morph('panel'+h2, {
			sync: true,
			style: 'width:188px;'
		}),
		//new Effect.Appear('panel_info'+cur, {sync: true}),
		new Effect.Fade('panel_info'+h2, {sync: true}),
		new Effect.Fade('panel_info'+h1, {sync: true}),
		new Effect.Appear('panel_screen'+h2, {
			sync: true,
			to: 0.5
		})
	], {
		duration: 0.8,
		delay: 0.1,
		queue: {position: 'end', scope: 'panels', limit: 1}
	});
}


Cufon.replace('h1,h2,h3');
Cufon.replace('h1', {
	fontFamily: 'maryjanesc',
	color: '-linear-gradient(#efc47e, #df7d00)',
	textShadow: '#4f350b 1px 1px'
});

Cufon.replace('h2', {
	color: '-linear-gradient(#997E53, #997E53)',
	textShadow: '#4f350b 1px 1px'
});

Cufon.replace('h3', {
	color: '-linear-gradient(#65add5, #2266b7)',
	textShadow: '#4f350b 1px 1px'
});

Cufon.replace('a.cufon', {
	hover: true
});

Cufon.replace('.cufon', {
	textShadow: '#4f350b 1px 1px'
});



Cufon.replace('.font_mjesc', {
	fontFamily: 'maryjanesc'
});

Cufon.replace('.panel_header', {
	textShadow: '#4f350b 1px 2px',
	fontFamily: 'maryjanesc'
});




