function initHeadMenu()
{
	// oznaceni polozky v submenu
	//url = window.location.pathname;
	url = window.location.protocol + '//' + window.location.host + window.location.pathname;

	jQuery("#headMenuItems a").each(function(){
		var href = jQuery(this).attr("href");
		if ( href == url) { jQuery(this).addClass("active") }
		
		if (href.indexOf('/press') != -1 && url.indexOf('/press/') != -1) jQuery(this).addClass("active");
	});
	
	


	// aktivace selectoru
	var item = jQuery("#headMenuItems .active").eq(0);
	if (item.length==0) var item = jQuery("#headMenuItems a").eq(0);

	var offset = item.position();
	var left = offset.left + 60;
	var width = item.outerWidth();

	jQuery("#headMenuSelector").css({
		width:width,
		left:left,
		display:'block'
		
	});
}

function loadTwitter(data)
{
	for (i in data)
	{
		if (i<3)
		{
			var hlink = /\s(ht|f)tp:\/\/([^ \,\;\:\!\)\(\"\'\<\>\f\n\r\t\v])+/g;
   			var text = (data[i].text.replace (hlink, function ($0,$1,$2) { s = $0.substring(1,$0.length); 
                                                   // remove trailing dots, if any
                                                   while (s.length>0 && s.charAt(s.length-1)=='.') 
                                                      s=s.substring(0,s.length-1);
                                                   // add hlink
                                                   return " " + s.link(s); 
                                                 }
                     ) 
           );
      $('#twitterFeed ul').append('<li class="text">' + text+ '</li>');
			//$('#' + 'homeTweetsCol' + (parseInt(i) + 2)).html(text);
		}
	}
}



var servicesActiveFrame = 0;

function scrollService()
{

	var off = 960;
	
	if (servicesActiveFrame == 0)
	{
		servicesActiveFrame = 1;
		jQuery('#sluzbyRozcestnikTable').animate({ left: '-='+off });
		
	} else { 
		servicesActiveFrame = 0;
		jQuery('#sluzbyRozcestnikTable').animate({ left: 0 });
		
	}

	var bullets = jQuery('#sluzbyRozcestnikNaviBullets .bullet');
	var abullet = jQuery('#sluzbyRozcestnikNaviBullets .active');	

	abullet.removeClass('active');
	 
	if (abullet.index() == 0) { bullets.eq(1).addClass('active'); }
	else { bullets.eq(0).addClass('active'); }

	console.log(bullets);
	
}


function headSlideshowNext(target)
{
	var buls = jQuery('#headSlideshowBullets a');
	var blocks = jQuery('#headSlideshow .frame');
	
	var active = jQuery('#headSlideshowBullets .active').eq(0);
	var index = active.index();
	var next = active.next();
	
	buls.removeClass('active');
	blocks.removeClass('active');
	
	if (target != undefined)
	{
		buls.eq(target).addClass('active');
		blocks.eq(target).addClass('active');

	} else
	{
		if (next.length != 0)
		{	
			next.addClass('active');		
			blocks.eq(index+1).addClass('active');
			
		} else {
			buls.eq(0).addClass('active');
			blocks.eq(0).addClass('active');
		}

	}
	
		
	
}


function pressImagesTitler(title, currentArray, currentIndex, currentOpts) {
	return jQuery('#'+title).html();
}

jQuery(window).load(function($) {

	initHeadMenu();

	jQuery('a.shift').live('click', function(event) {
	 jQuery('div#main').load($(this).attr('href'));
	 return false;
	});

		
	jQuery('#sluzbyRozcestnikTable .arrow.top').click(function(){
		scrollServiceRight();
  		return false;
	});

	jQuery('#sluzbyRozcestnikTable .arrow.bottom').click(function(){
		scrollServiceLeft();
  		return false;
	});
	
	jQuery('#homeReference').mouseenter(function() {
  		jQuery(this).animate({height:'160px'});
	});

	jQuery('#homeReference').mouseout(function() {
  		jQuery(this).animate({height:'75px'});
	});

	if (jQuery('#intro').length != 0) var player = new MediaElementPlayer('#intro', {autoplay: true});

	if (jQuery('#headSlideshow').length != 0)
	{
		jQuery('#headSlideshowBullets a').click(function(){
			headSlideshowNext(jQuery(this).index());
			return false; 
		});
		
		
		setInterval('headSlideshowNext()', 3000);
	}
	
	
	// trochu ochcavka, spoleham na to, ze okno ma jen dve mozne pozice, ktere staci jen prohodit
	jQuery('#sluzbyRozcestnikNavi a').click(function(){
		scrollService();
  		return false;
	});	
	
	if (jQuery('#pressImages .images a').length != 0) jQuery("#pressImages .images a").fancybox({ 'titlePosition':'inside', 'titleFormat':pressImagesTitler});
	
	

});


