/**
 * @author karlofthedead
 */

// Firebug: avoid errors in other browsers
if ( !window.console || !console.firebug ) {
    var names = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml',
    'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'];

    window.console = {};
    var i = 0, n = names.length;
    for ( ; i < n; i++ ) { window.console[names[i]] = function() {}; }
}

// global variables declaration
var base = document.getElementsByTagName( 'base' )[0].getAttribute( 'href' );
var lang = document.getElementsByTagName( 'html' )[0].getAttribute( 'xml:lang' );

var i18n;

// initialization phase
jQuery( function() {
	
	Navigation.init();
	
	// loading translations
	i18n = new Translate( translations, lang );
	// Shadowbox initialization, only if loaded
	if ( !!Shadowbox ) {
		Shadowbox.init( { /*skipSetup: true*/ } );
	}

	// Tooltips initialization, only if loaded
	if ( !!jQuery.tooltip ) {
		jQuery( '*[title]' ).tooltip( {
			track    : true,
			delay    : 0,
			showURL  : false,
			showBody : ' - ',
			fade     : 250
		} );
	}

	if($.fn.cycle){
		$('#catalogIndexList').cycle({ 
			fx:     'fade', 
			speed:   500, 
			timeout: 3000, 
			prev:   '#navPrev', 
			next:   '#navNext', 
			pause:   1 
		});
	

		$('.newsBlock div.list ul').each(function(){ 
			var navprev = $('.prevNav',$(this).parent().parent());
			var navnext = $('.nextNav',$(this).parent().parent());
			
			$(this).cycle({ 
				fx:     'fade', 
				speed:   500, 
				timeout: 3500, 
				prev:   navprev, 
				next:   navnext, 
				pause:   1 
			});
		});
	}
	
	
	$('div.preview div.map a.toggle').click(function(e){
		e.preventDefault();
		$('#map_canvas',$(this).parent()).toggle(300);
		return false;
	});
	
	$('table.productReferences tbody tr:even').addClass('even');
	
	$('#footer .navigation li').not(':last').append(' | ');
	
	/** shadowbox click next */
	$('#sb-container').delegate('img#sb-player','click',function(){ Shadowbox.next();});
	
} );

var Navigation = {

		init: function(){
	
			$('a.printButton').click(function(){ window.print(); return false;});
			$('#header ul.navigation ul').hide();

			$('#header ul.navigation ul').parent('li')
				.bind('mouseover',function(){
					$('ul',this).show();
					$(this).addClass('active');
				})
				.bind('mouseout',function(){
					$('ul',this).hide();
					$(this).removeClass('active')
				});
			
		}
}
