$(document).ready(function(){

	$('.i-text').focus(function(){
		if($(this).attr("title") == $(this).val()) $(this).val('');
	}).blur(function(){
		if($(this).val() == '') $(this).val($(this).attr("title"));
	});

	$('#header-authorization-open-close').click(function(){
		if($(this).parent().hasClass('opened')) {
			$(this).parent().animate({"top": "-72px"}, "slow");
			$(this).parent().removeClass('opened');
		} else {
			$(this).parent().animate({"top": "0px"}, "slow");
			$(this).parent().addClass('opened');
		}
	});

	$('#header-country-open-close').click(function(){
		if($(this).parent().hasClass('opened')) {
			$(this).parent().animate({"top": "0px"}, "slow");
			$(this).parent().removeClass('opened');
		} else {
			$(this).parent().animate({"top": "373px"}, "slow");
			$(this).parent().addClass('opened');
		}
	});

	$('.fce_expandbl-item dt').click(function(){
		if($(this).parent().hasClass('collapsed')) {
			$(this).parent().removeClass('collapsed');
		} else {
			$(this).parent().addClass('collapsed');
		}
		if($(this).parent().parent().hasClass('fce_expandbl-2')) {
			$(this).find('span').slideToggle();
		} else {
			$(this).find('span').toggle();
		}
	});
	$('.fce_expandbl-toggle span.exp-active').click(function(){
		$(this).parent().find('span').toggle();
		$(this).parent().parent().find('.fce_expandbl-item.collapsed dt').find('span').toggle();
		$(this).parent().parent().find('.fce_expandbl-item').removeClass('collapsed');
	});
	$('.fce_expandbl-toggle span.exp-hidden').click(function(){
		$(this).parent().find('span').toggle();
		$(this).parent().parent().find('.fce_expandbl-item dt').find('span').toggle();
		$(this).parent().parent().find('.fce_expandbl-item').addClass('collapsed');
	});

	$('.simple-box dt').click(function(){
		if($(this).parent().hasClass('opened')) {
			$(this).parent().removeClass('opened');
			$(this).parent().addClass('closed');
			$(this).parent().find('dd .content').fadeOut("slow");
			$(this).parent().find('dd').animate({"height": "0px"}, "slow");
		} else {
			$(this).parent().addClass('opened');
			$(this).parent().removeClass('closed');
			$(this).parent().find('dd .content').fadeIn("slow");
			$(this).parent().find('dd').animate({"height": ($(this).parent().find('dd .content').height()+11)+"px"}, "slow");
		}
	});

	$('.fce_tabs-items li').click(function(){
		if($(this).hasClass('active')) {

		} else {
			elements = this.parentNode.parentNode.getElementsByTagName('div');
			for(i=0;i<elements.length;i++) {
				if(elements[i].className == 'fce_tabs-item') {
					elements[i].style.display = 'none';
				}
			}
			document.getElementById(this.className).style.display = 'block';

			$(this).parent().find('li').removeClass('active');
			$(this).addClass('active');
/*
			new_active_div = $(this).parent().parent().find('#' + $(this).attr("class"));
			all_divs = $(this).parent().parent().find('.fce_tabs-item');

			$(this).parent().find('li').removeClass('active');
			$(this).addClass('active');

			all_divs.css('display', 'none');
			new_active_div.css('display', 'block');
*/
		}
	});

	if($('.icon-print')){
		$('.icon-print').click(function () {
			chageToPrintStyle();
		});
/*
		$('.icon-print').each(function(i){
			$(this).bind("click", function(e){
				chageToPrintStyle();
			})
		});
*/
	}

	if($('.cta') && jQuery.browser.msie && jQuery.browser.version == '6.0'){
		DD_belatedPNG.fix('.cta-top');
		DD_belatedPNG.fix('.cta-bottom');

		$('.cta').each(function(i){
			$(this).bind("mouseover", function(e){
				toggleCTA(this);
			})
			$(this).bind("mouseout", function(e){
				toggleCTA(this);
			})
		})
	}
/*
	if($('#side-menu')){
		$('#side-menu a').each(function(i){
			$(this).bind("mouseover", function(e){
				if(!$(this).hasClass('active')){
					this.style.color = "#ff9311";
					this.style.background = "url(images/left-menu-ul-li-a.png) repeat-y";
				}
			})
			$(this).bind("mouseout", function(e){
				if(!$(this).hasClass('active')){
					$(this).animate({color: '#243382'});
					$(this).animate({background: ''});
				}
			})

		})
	}
*/
	$('.menu-v :not(.active)').mouseover(function(){
		$(this).find('a').css({'background' : ''}).css({'background' : 'url(fileadmin/templates/dqs/images/left-menu-ul-li-a.png) repeat-y', 'color' : '#ff9311'});
	}).mouseout(function(){
		$(this).find('a').css({'background' : '#fafafe'}).animate({backgroundColor: 'userlightgray', color: '#243382'}, 600);
	});

	$('.simple-box.closed').each(function (i) {
		$(this).find('dd').css({'height' : '0px'});
	    $(this).find('.content').css({'display' : 'none'});
	});

	if($('.tx-ttnews-browsebox').length) $('.tx-ttnews-browsebox').find('.active').children()[0].className = 'active';

});

function init() {

}

function chageToPrintStyle(){
	if(document.getElementById('printstyles')){
		document.getElementById('printstyles').media='all';
		window.print();
		document.getElementById('printstyles').media='print';
	}
}

function toggleCTA(srcObj){
	if($(srcObj).hasClass('hover')){
		$(srcObj).removeClass('hover');
	}else{
		$(srcObj).addClass('hover');
	}
}

$(function(){
	
	$('.b-track-list a').each(function(){
		$(this).attr('title', 'Click to play/stop track');
	});
	$('.b-track-list a').click(function() {
		//console.log('done');
		var sMP3 = $(this).attr('href');
		
		if($(this).hasClass('played')){
			$("#jpId").jPlayer("stop");
			$(this).removeClass('loading played');
		} else {
			$('.b-track-list a').removeClass('loading played')
			$("#jpId").jPlayer( "clearFile" ).jPlayer("setFile", sMP3).jPlayer("play");
			$(this).addClass('loading played')
			
			var timeout = setTimeout ("$('.b-track-list a').removeClass('loading')", 5000);
		}
		
		return false;
	});
	
	$("#jpId").jPlayer( {
		swfPath: "/js/"
	});

});

