
var tops;
var makslinieki;
var tabs;
var repgroup, rep;
var comments;


if(LANG == "ru") {
	
	Cufon.replace('div#content .cufon', { fontFamily: 'Helvetica_Light-Normal' });
	Cufon.replace('div.teatri .title', { fontFamily: 'Helvetica_Light-Normal' });
	Cufon.replace('div#content .cufon', { fontFamily: 'Helvetica_Light-Normal' });
	Cufon.replace('div.box .image span.desc .title', { fontFamily: 'Helvetica_Light-Normal' });	

} else {

	Cufon.replace('div.banners .title', { fontFamily: 'Geogrotesque Lg' });
	Cufon.replace('div.teatri .title', { fontFamily: 'Geogrotesque Lg' });
	Cufon.replace('div#content .cufon', { fontFamily: 'Geogrotesque Lg' });
	Cufon.replace('div.box .image span.desc .title', { fontFamily: 'Geogrotesque Rg' });
	
}



if(typeof AudioPlayer != "undefined") {

	AudioPlayer.setup(BASE_URL + "js/audio-player/player.swf?ver=20080825040617", 
			{
				width:"460",
				animation:"yes",
				encode:"no",
				initialvolume:"60",
				remaining:"no",
				noinfo:"yes",
				buffer:"5",
				checkpolicy:"no",
				rtl:"no",
				bg:"E5E5E5",
				text:"333333",
				leftbg:"CCCCCC",
				lefticon:"333333",
				volslider:"666666",
				voltrack:"FFFFFF",
				rightbg:"bbbdbb",
				rightbghover:"999999",
				righticon:"333333",
				righticonhover:"17c5fa",
				track:"FFFFFF",
				loader:"17c5fa",
				border:"CCCCCC",
				tracker:"DDDDDD",
				skip:"666666",
				pagebg:"FFFFFF",
				transparentpagebg:"yes"
			});

}







$(document).ready(function(){
	
	tops = new Tops( $('div#topofthetops') );
	

	// lightbox
	
	if($('a.zoom').length > 0) {
		
		$('a.zoom').lightbox();
	}
	
    
    
    
    // top menu
    
    $('div#menu-top ul.menu-top > li').hover(function(){
    	
    	$('img', this).attr('src', $('img', this).attr('src').replace(0,1) );
    	$('ul.menu-top-sub', this).slideDown();
    	
    }, function(){
    	
    	$('img', this).attr('src', $('img', this).attr('src').replace(1,0) );
    	$('ul.menu-top-sub', this).slideUp('fast', function(){
    		
    		$(this).clearQueue();
    	});
    	
    });
    
    
    
    // top banner
     
    tops = new Tops( $('div#header div.banners') );
    
    

    
    // fp box
    
    $('div#content-fp div.boxes div.box a.image').hover(function(){
    	
    	$('span.date', this).slideDown();
    	
    }, function(){
    	
    	$('span.date', this).slideUp();
    	
    })
    
    
    $('div#content-fp div.boxes div.bottoms a.more').click(function(){
    	
    	$('div#content-fp div#more').slideDown();
    	
    	$('div.bottom a.more').hide();
    	$('div.bottom a.all').show();
    	
    	return false;
    });
    
    
    // makslinieki
    
    markslinieki = new Accordeon( $('div#content.content-makslinieki ul.makslinieki') );
 
    
    // tabs
    
   tabs = new Tabs( $('div#content div.tabs') );
    
   
   // repertuars
 
   repgroups = new Accordeon( $('div#content.content-repertuars ul.repertuars') );
   rep = new Rep( $('div.izrades-group table.izrades') );
   
   
   
   
   // decorate select box
   
   if($("select").length > 0) {
   
	   $("select").selectbox().bind('change', function(){
		   
		   $(this).parents('form').submit();
	   });
   		
   }
 
   
   // cosmodroms
   
   $('a#cosmodroms').hover(function(){
	   $(this).animate({ width: 150 }, 500);
   }, function(){
	   $(this).animate({ width: 26 }, 500);
   });
   
   
   
   comments = new Comments('form#comments');
   

   
});





function youtube(url) {
	
	var so = new SWFObject(url, 'video', "480", "335", "9", "#FFFFFF"); 	
	so.addParam("wmode","transparent");
	so.write('video');
	
	return false;
}



function audio(id, url) {
	
	AudioPlayer.embed(id, {soundFile: url});
}






function more( el ) {
	
	var td = $('a.pilnais').parents('td');
	
	if( $('#more').is(':visible') ) {
		td.css('height', '375px');
	} else {
		td.css('height', 'auto');	
	}
		
	$('a.pilnais').toggle();
	$('#more').toggle();
	
	return false;
}





function GMap(lat, lng, obj) {


	if($('#' + obj).length == 0)
		return;


	  
    var myLatlng = new google.maps.LatLng(lat, lng);
    
    var myOptions = {
      zoom: 15,
      center: myLatlng,
      mapTypeControl: false,
      navigationControl: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    
    var map = new google.maps.Map(document.getElementById(obj), myOptions);
    
    var marker = new google.maps.Marker({
        position: myLatlng, 
        map: map,
        title:""
    });
	
}












var Tops = function(el) {
	
	var _self 	= this;
	var t 		= null;
	var curr	= 0;
	
	
	this.sw = function() {
		
		// active top
		
		var banners = $('a.banner', el);

		banners.fadeOut('slow');
		$(banners.get(curr)).fadeIn('slow');

	}
	
	


	
	this.next = function() {
		
		var banners = $('a.banner', el);
		
		curr += 1;
		
		if(curr >= banners.length)
			curr = 0;
		
		_self.sw()
	}
	
	
	
	this.prev = function() {
		
		var banners = $('a.banner', el);
		
		curr -= 1;
		
		if(curr < 0)
			curr = banners.length;
		
		_self.sw()
	}
	
	
	
	if( $(el).length == 0 )
		return;
	
	
	
	// init
	
	this.sw();
	
	
	// timer
	
	if( !$(el).hasClass('skip') ) {
	
		_self.t = setInterval(_self.next, 4000);
	}

	// arrows

	$('ul.arrows li a.next', el).click(function(){

		clearInterval(_self.t);

		_self.next();
		
	});
	
	$('ul.arrows li a.prev', el).click(function(){

		clearInterval(_self.t);

		_self.prev();
		
	});
		
}





function Accordeon(el) {
	
	var _self = this;
	
	
	this.sw = function( group ) {
		
		var li = $(group).parents('li');
		
		// close all
		
		// $('div.group', el).slideUp();
		$('div.group', el).hide();
		
		$('a.group', el).removeClass('active');
		$('li', el).removeClass('active');
		
		// open
		
		// $('div.group', li).slideDown();
		$('div.group', li).show();
		
		$('a.group', li).addClass('active');
		$(li).addClass('active');
	}
	
	
	
	// init

	
	if($.browser.msie || !jQuery.support.boxModel) {
	
		// none
		
		
	} else { 
	
		
		$('li a.active', el).each(function(){
			
			_self.sw(this);
		});
		
		$('li a.group', el).click(function(){
			
			if( !$(this).hasClass('active') ) {
				_self.sw(this);
			}
			
			return false;
		})
		
		
		// open first (if none)
		
		
		if( $('a.group.active', el).length == 0 ) {
		
			_self.sw( $('a.group:first', el) );
		}
	
	}

	return;
}







function Tabs( el ) {
	
	
	var _self = this;
	
	
	this.sw = function( n ) {
		
		$('div.tab', el).hide();
		$( $('div.tab', el).get(n) ).show();
		
		$('ul.tabs li a', el).removeClass('active');
		$( $('ul.tabs li a', el).get(n) ).addClass('active');
		
		_self.off();
		_self.on( n );
	}
	
	
	this.on = function(n) {
		
		var img = $('img', $('ul.tabs li a', el).get(n) ); 
		img.attr('src', img.attr('src').replace(0,1) );
	}
	
	
	this.off = function() {
		
		$('ul.tabs li a', el).each(function(){
			
			if( !$(this).hasClass('active') )
				$('img', this).attr('src', $('img', this).attr('src').replace(1,0) );
		})
		
	}
	
	
	// init

	if( $('ul li', el).length == 0 )
		return;
	
	$('ul.tabs li a', el).click(function(){
		
		var n = $('ul.tabs li a', el).index(this);
		_self.sw( n );
		
		//return false;
	});

	
	// open hash of first
	
	var h;
	var hash = window.location.hash;
	
	$('ul.tabs li a', el).each(function(){
		
		if( $(this).attr('href') == hash ) {
			
			h = $('ul.tabs li a', el).index(this);
			_self.sw( h );

		}
	})
	
	if(typeof h == "undefined") {
	
		_self.sw( 0 );
	}
	
	
	
	
	
    $('ul.tabs li a', el).hover(function(){
    	
    	var n = $('ul.tabs li a', el).index(this);
    	_self.on( n );
    	
    }, function(){
    	
    	_self.off();
    	
    });
	
	
}




var Rep = function( el ) {
	
	var _self = this;
	
	
	this.sw = function( it ) {
		
		var id = $(it).parents('tr').attr('id');
		var co = $('tr#c-' + id + '.comments');
		
		co.toggle();
		
		if( co.is(':visible') ) {

			$('a.more', $(it).parents('tr') ).addClass('active');
			
		} else {
			
			$('a.more', $(it).parents('tr') ).removeClass('active');
			
		}

	}
	
	
	
	
	this.doSubmit = function() {
	
		$('div#content.content-repertuars form#filter').submit();
	}
	
	
	
	
	
	
	if(!el)
		return;
	
	
	// init
	

	

	if($.browser.msie || !jQuery.support.boxModel) {
	
		// do nothing
		
	} else {
	
		
		// roll
		
		$('tr', el).hover(function(){
			
			_self.bg = $('td.roll', this).css('background');
			
			// td
			$('td.roll', this).css('background', 'white');
			
			// ticket
			$('td a.ticket', this).addClass('active');
			
			// date
			var group = $(this).parents('div.izrades-group');
			group.css('background', 'white');
			
		}, function(){
			
			$('td.roll', this).css('background', _self.bg);
			$('td a.ticket', this).removeClass('active');
			
			// date
			var group = $(this).parents('div.izrades-group');
			$(group).css('background', _self.bg);
		});
	
			
	}


	
	$('tr td a.more, tr td a.more2', el).click(function(){
		
		_self.sw( this );
		return false;
	})
	
	
	
	// datepicker
	   
	$('#date').datepicker({ 
		altField: 'input#date', 
		altFormat: 'yy-mm-dd',
		firstDay: 1, 
		dateFormat: 'yy-mm-dd',
		
		showOn: 'button', buttonImage: BASE_URL + 'images/repertuars/kalendars.jpg', buttonImageOnly: 'true',
		
		onSelect: function() {
			//$(this).val("");
			_self.doSubmit();
		}
	});
	
	
	
	$('div#content.content-repertuars form#filter select').change(function(){
		
		_self.doSubmit();
	});
   
	
}






var Comments = function(el) {
	
	var _self = this;
	
	
	this.add = function() {
		
		$('div#msg img', el).show();
		
		$('input#CID', el).val( $('input#CID', el).val().substr(0,5) );
		$('input.submit').attr("disabled", true);
		
		$.post( location.href, 
				$(el).serialize(),
				function(data){

			
					$('input#name', el).val(" ");
					$('input#email', el).val(" ");
					$('textarea', el).val(" ");
					
			
					$('div#msg img', el).hide();
					$('div#msg span', el).show();
					
				}, 
				"html");		
	}
	
	
	
	// init
	
}










