$(document).ready(function() {

    var pole = location.href.split('/');
	var region = '/'+pole[3];
	if(pole[3])
	{
		if(pole[3] == 'rubrika')
		{
			$("div#header ul.menuRegions li:first").addClass('selected');
			$("div#header ul.sub li:first").addClass('selected');
		}
		
	}
	var temp = $("div#header ul.menuRegions li a[href='"+region+"']").parent().addClass('selected');
	
	var portal = region+'/'+pole[4];
	
	 $("ul.menuRegions a[href='"+portal+"']").parent().addClass('selected');
	 
	
	if(pole[4])
	{
		// alert(pole[4]);
		if(pole[3] != 'rubrika')
		{
			$("ul.sub li a[class='all']").parent().removeClass('selected');
		}
		
		
	}
	

	// Kliknutí na regiony (Ostravsko, Karvinsko,...)
	$("div#header ul.menuRegions li a").click(function () {
		/*$('div#header ul.menuRegions li').removeClass('selected');
		$(this).parent().addClass('selected');*/
		
	});
	
	// Kliknutí na portál (Ostrava, Karviná, ...)
	$("div#header ul.menuPortals li a").click(function () {
		
		/*$('div#header ul.menuPortals li').removeClass('selected');
	
		$(this).parent().addClass('selected');
		*/
		
	});
	
	// Kliknutí na zvolené téma
	$("div#header ul.menuThemes li a").click(function () {
		
		$('div#header ul.menuThemes li.selected:first a.left').remove();
		$('div#header ul.menuThemes li.selected:first a.right').remove();
		$('div#header ul.menuThemes li').removeClass('selected');
		
		
		$(this).addClass('main');
		// $(this).parent().addClass('selected');
		$(this).parent().prepend('<a href = "/" class = "left"></a>');	
		$(this).parent().prepend('<a href = "/" class = "right"></a>');	
		
		return false;
	});
	
	
	// zobrazení regionů ve vyhledavani
    $('div#header form:first input[type=text]').click(function(){
        
        var inputName = $('div#header form:first input[type=text]').attr('value');
        if(inputName == 'hledej článek'){
            $('div#header form:first input[type=text]').val('');
            $('div#header form:first input[type=text]').css("color","#000000");
        }
    
         $('div#header form:first div:first').fadeIn(500);
         
    });

	
	
	// smazani textu v poli pro vyhledavani
	$('div#header form:first div:first a.clear').click(function(){
		$('div#header form:first input[type=text]').val('');
		return false;
		
	});
	
	// skytí nabídky pro vyhledavani
	$('div#header form:first div:first a.close').click(function(){
		$('div#header form:first div:first').fadeOut(500);
		return false;
		
	});
	
	$("#header form:first div:first input.commonRadion").click(function(){
		
		 $("#header form div input.all").removeAttr("checked");
		
		 if($(this).attr("checked") == false)
		 {
		  $(this).removeAttr("checked");
		 
		  if($("input.commonRadion[@checked]").length == 0)
		  {
		  $("input.all").attr("checked",true);
		 
		  }
		 
		  } // end if
		 
	 }); 
	
	

	// tisk clanku
	$('a.print').click(function(){
		$('a.print').remove();
		$('link[media=print]').attr('href','/Content/Css/PrintPreview.css');
		
		window.print(); 
		return false;
	
	 }); 
	
	
	
	$('div#header div.specialMenu a.others').toggle(function(){ 
		$('div#header div.specialMenu ul li.other').css('display','block'); 
		},function(){ 
		$('div#header div.specialMenu ul li.other').css('display','none');  
		});
	
	// Efekt menici ho se menu v hlavicce (specialy)
	firstLinkHref = $('#header div.specialMenu ul li:first a').attr('href');
	firstLinkValue = $('#header div.specialMenu ul li:first a').text();
	specialMenuCounter = 0;
	EffectSpecialsMenu();
	
		
});


function LoadThemes()
{
	$('div#navigation ul.menu li').removeClass('selected');
	$('div#navigation ul.menu li').eq(0).addClass('selected');
	
	
	$.ajax({
		  url: "/ajax/themes",
		  cache: false,
		  success: function(html){
		//	$("div#frameList").css("display","none");
			
		    $("div#navigation div.frame").html(html);
		    
		 //   $("div#frameList").fadeIn(450);
		  },
		  complete: function (XMLHttpRequest, textStatus) {
			 
		  } 
		  
	});
	return false;
}

function LoadWheather()
{
	$('div#navigation ul.menu li').removeClass('selected');
	$('div#navigation ul.menu li a[@href=pocasi]').parent().addClass('selected');
	$.ajax({
		  url: "/ajax/wheather",
		  cache: false,
		  success: function(html){
		//	$("div#frameList").css("display","none");
			
		    $("div#navigation div.frame").html(html);
		    
		 //   $("div#frameList").fadeIn(450);
		  },
		  complete: function (XMLHttpRequest, textStatus) {
			
		  } 
		  
	});
	return false;
} // end method LoadWeather

function LoadTraffic()
{
	$('div#navigation ul.menu li').removeClass('selected');
	$('div#navigation ul.menu li a[@href=doprava]').parent().addClass('selected');
	$.ajax({
		  url: "/ajax/traffic",
		  cache: false,
		  success: function(html){
		//	$("div#frameList").css("display","none");
			
		    $("div#navigation div.frame").html(html);
		    
		 //   $("div#frameList").fadeIn(450);
		  },
		  complete: function (XMLHttpRequest, textStatus) {
			
		  } 
		  
	});
	return false;
} // end method LoadWeather


function LoadPersonalities()
{
	$('div#navigation ul.menu li').removeClass('selected');
	$('div#navigation ul.menu li a[@href=osobnosti]').parent().addClass('selected');
	$.ajax({
		  url: "/ajax/personalities",
		  cache: false,
		  success: function(html){
		//	$("div#frameList").css("display","none");
			
		    $("div#navigation div.frame").html(html);
		    
		 //   $("div#frameList").fadeIn(450);
		  },
		  complete: function (XMLHttpRequest, textStatus) {
			 
		  } 
		  
	});
	return false;
} // end method Load


// Obsluha tlačítka Tipy v záložce v Navigation (vpravo)
function LoadTips()
{
	$('div#navigation ul.menu li').removeClass('selected');
	$('div#navigation ul.menu li a[@href=tipy]').parent().addClass('selected');
	$.ajax({
		  url: "/ajax/tips",
		  cache: false,
		  success: function(html){
		//	$("div#frameList").css("display","none");
			
		    $("div#navigation div.frame").html(html);
		    
		 //   $("div#frameList").fadeIn(450);
		  },
		  complete: function (XMLHttpRequest, textStatus) {
			 
		  } 
		  
	});
	return false;
} // end method Load Tips


function LoadSelectedTheme(id)
{
	$('div#navigation ul.menu li').removeClass('selected');
	$('div#navigation ul.menu li a[@href=temata]').parent().addClass('selected');
	
	
	
	$.ajax({
		  url: "/ajax/themes/"+id,
		  cache: false,
		  success: function(html){
		//	$("div#frameList").css("display","none");
			
		    $("div#navigation div.frame").html(html);
		    
		 //   $("div#frameList").fadeIn(450);
		 
		  },
		  complete: function (XMLHttpRequest, textStatus) {
			 
		  } 
		  
	});
	return false;
}

function LoadDiscussion(isForm,themeID) 
{
	
	
	$.ajax({
		  url: "/ajax/discussion/"+themeID,
		  cache: false,
		  success: function(html){
			$('div#left').attr('class', 'theme discussion');
		    $("div#left").html(html);
		    
		 //   $("div#frameList").fadeIn(450);
		  },
		  complete: function (XMLHttpRequest, textStatus) {
			  if(isForm)
			  {
				  $("div.theme form").slideDown(500);
					
			  }
		  } 
		  
	});
	
	
	
	return false;
	
	
} // end method LoadDiscussion


function LoadSpecialDiscussion(themeID) {
	
			  $("div.theme form.specialDiscussionForm").slideDown(500);
	
	
	
	
	return false;
}

function DisableCommentForm()
{
	$("div.theme form").slideUp(500);

}
/*
function InsertComment(themeID) {
	
	var message = $('div#left form:first textarea:first').attr('value');
	var firstName = $("div#left form:first input[name='firstName']").attr('value');
	var surName = $("div#left form:first input[name='surName']").attr('value');
	
	
	$.ajax({
		  type: "POST",
		  data: "message=" + message+"&firstName="+firstName+"&surName="+surName,
		  url: "/ajax/discussion/insert/"+themeID,
		  cache: false,
		  success: function(html){
				$("div#left").html(html);
		    
		 //   $("div#frameList").fadeIn(450);
		  },
		  complete: function (XMLHttpRequest, textStatus) {
			  
		  } 
		  
	});
}
*/
function InsertComment(type,objectID) {
	
	if(type == 'special')
	{
		var message = $('div#left div.discussion form:first textarea:first').attr('value');
		var firstName = $("div#left div.discussion form:first input[name='firstName']").attr('value');
		var surName = $("div#left div.discussion form:first input[name='surName']").attr('value');
		
	}
	
	if(type == 'theme')
	{
		var message = $('div#left form:first textarea:first').attr('value');
		var firstName = $("div#left form:first input[name='firstName']").attr('value');
		var surName = $("div#left form:first input[name='surName']").attr('value');
		
	}

	$.ajax({
		  type: "POST",
		  data: "message=" + message+"&firstName="+firstName+"&surName="+surName,
		  url: "/ajax/discussion/insert/"+type+"/"+objectID,
		  cache: false,
		  success: function(html){
		
			if(type == 'special')
			{
				$("div#left div.discussion").html(html);
				
			}
			
			if(type == 'theme')
			{
				$("div#left").html(html);
				
			}
				
		    
		
		  },
		  complete: function (XMLHttpRequest, textStatus) {
			  
		  } 
		  
	});
	
}


function Vote(surveyID, type, objectID ) {
	
	//alert(surveyID);
//	var var_name = $("input[name='radio_name']:checked").val();

	
	var choice = $('#survey'+surveyID+' input[type=radio]:checked').attr('id');
	
	
	choice = choice.split('-');
	choiceID = choice[1];
	// alert(choiceID);
	
	
	$.ajax({
		  type: "POST",
		  url: "/ajax/survey/"+surveyID+"/"+choiceID+"/"+type+"/"+objectID,
		  cache: false,
		  success: function(html){
			// $("div#left").html(html);
			if(type == 'theme')
			{
				$("div#navigation div.frame").html(html);
				//alert('theme');
			}
			
			if(type == 'special')
			{
				//alert('special');
				$("div#wrapper div.specialSurveysFrame").html(html);
			}
			
		    
		 //   $("div#frameList").fadeIn(450);
		  },
		  complete: function (XMLHttpRequest, textStatus) {
			  
		  } 
		  
	});
	
	
	
	
} // end of method Vote


function Search() {
	
	
	
} // end of method Search

function LoadMailForm(){

    $("form.sendMail").slideDown(500);

}// end of method LoadMailForm

function CloseMailForm(){

    $("form.sendMail").slideUp(500);

}// end of method LoadMailForm

function SendMail(type){

    yourName = $("form.sendMail input[name='yourName']").attr('value');
    reciver = $("form.sendMail input[name='reciver']").attr('value');
    text = $("form.sendMail textarea").attr('value');
    hid = $("form.sendMail input[name='hid']").attr('value');

    $.ajax({
            type: "POST",
            data: "yourName="+yourName+"&reciver="+reciver+"&text="+text+"&type="+type+"&hid="+hid  ,
            url: "/ajax/mail",
            cache: false,
            success: function(html){
               
               $("form.sendMail").html(html);
              
            },
            complete: function (XMLHttpRequest, textStatus) {
                 
            } 
            
     });

}

function DisableSpecialCommentForm() {
	$('div.theme form.specialDiscussionForm').slideUp(500);
}
function ShowNextSpecialVideos() {
	$('div#navigation div.othersVideos').css('display','block');
	$('div#navigation h3').eq(1).remove();
}
function ShowNextThemeVideos() {
	$('div#navigation div.player2 div.othersThemeVideos ').css('display','block');
	$('div#navigation div.player2 h3').eq(0).remove();
}
function ShowNextSpecialPhotos() {
	$('div#navigation div.otherImageGallery').css('display','block');
	$('div#navigation h3.nextPhotos').remove();
}




 function EffectSpecialsMenu()
 {
	
	 if(specialMenuCounter%2 == 0)
	 { 
		 $('#header div.specialMenu ul li:first a').text(firstLinkValue); 
		 $('#header div.specialMenu ul li:first a').attr('href',firstLinkHref);
	 }
	 else
	 { 
		 $('#header div.specialMenu ul li:first a').text('SPECIÁLY'); 
		 $('#header div.specialMenu ul li:first a').attr('href','/specialy');
	 } 
	 
	 specialMenuCounter = specialMenuCounter + 1;
	 
	 setTimeout(EffectSpecialsMenu,3500);

 } // end of method zobrazNovinky
 
function themeListRolout(){

    if($('div#navigation div.themes ul.others').css('display') == "block"){
        $('div#navigation div.themes ul.others').css('display','none');
    }else{
        $('div#navigation div.themes ul.others').css('display','block'); 
    } 

}

function loadRightPlayer(id){
/*	var so = new SWFObject('/public/player/player1.swf','mpl1','400','225','9');
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','always');
	so.addParam('wmode','opaque');
	so.addVariable('file',sessvars.movie.video.split('~')[0]+'_www.mp4');
	so.addVariable('plugins','hd-1');
	so.addVariable('hd.file',sessvars.movie.video.split('~')[0]+'_tv.mp4');
	so.addVariable('streamer','rtmp://213.195.200.42/tvportaly');
	so.addVariable('hd.state','false');
	so.addVariable('autostart','false');
	so.addVariable('stretching','fill');
	so.addVariable('image',sessvars.nahled);
	so.write(id);*/
	
	var requiredMajorVersion = 9;
var requiredMinorVersion = 0;
var requiredRevision = 115;
var hasProductInstall = DetectFlashVer(6, 0, 65);
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
if ( hasProductInstall && !hasReqestedVersion ) {
	var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
	var MMredirectURL = window.location;
	document.title = document.title.slice(0, 47) + " - Flash Player Installation";
	var MMdoctitle = document.title;
	AC_FL_RunContent(
		"src", "/public/player/playerProductInstall",
		"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
		"width", "550",
		"height", "300",
		"align", "middle",
		"id", "detectionExample",
		"quality", "high",
		"bgcolor", "#3A6EA5",
		"name", "detectionExample",
		"allowScriptAccess","always",
		"type", "application/x-shockwave-flash",
		"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);
} else if (hasReqestedVersion) {
    var so = new SWFObject('http://light.polar.cz/player/player_logo_HD.swf','mpl1','400','257','9');
    so.addParam('allowfullscreen','true');
    so.addParam('allowscriptaccess','always');
    so.addParam('wmode','transparent');
    so.addVariable('file','http://light.polar.cz/videa/tvportaly.cz/videa/publikovano/'+sessvars.movie.video.split('~')[0]+'_www.mp4');
	//so.addVariable('plugins','hd-1');
	so.addVariable('hd.file','http://light.polar.cz/videa/tvportaly.cz/videa/publikovano/'+sessvars.movie.video.split('~')[0]+'_tv.mp4');
	//so.addVariable('streamer','rtmpt://213.195.200.44:80/tvportaly');
	so.addVariable('hd.state','false');
	so.addVariable('autostart','false');
	so.addVariable('stretching','uniform');
	so.addVariable('type','lighttpd');
  so.addVariable('bufferlength','2');
	so.addVariable('image',sessvars.nahled);
    so.write(id);
} else {
	var alternateContent = 'Pro pÅehrÃ¡nÃ­ videa je vyÅ¾adovÃ¡n Adobe Flash Player. '
	+ '<a href=http://www.adobe.com/go/getflash/>StÃ¡hnout Flash Player</a>';
	document.write(alternateContent);
}

}	


