$(document).ready(function(){
	// apply ie6 pngfix to all png images 
	$('img[@src$=.png]').ifixpng();
	$('a.arrDown').parent().append('<a href="#" class="expandArr">expand</a>');	
	$('#week1 > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle' } });
	$('ul.subTabs').tabs({ fxFade: true, fxSpeed: 'normal' });
	$('ul.fotovideoTabs').tabs({ fxFade: true, fxSpeed: 'normal' });
	$('ul.dayHeadlines li:last-child').css({ "border-bottom": "none" });
	$('ul.footerMenu li:last-child').css({ "border-right": "none" });
	$('ul.eventCalendar li:last-child').css({ "border-bottom": "none" });
	$('ul.tabNav li:last-child').css({ "margin-right": "0" });
	$('#frontNews .newsColumn:last-child').css({ "border-right": "none", "padding-right": "0" });
	$('#frontNews .newsColumn:first-child').css({ "padding-left": "0" });
	$('.modeList:last-child').css({ "padding-right": "0" });
	$('.faceBox:last-child').css({ "margin-right": "0" });
	$('.newsColumn').equalHeight();
	$('.artikelRight ul li:first-child').css({"border-top": "1px dotted #999"});
	$('ul.konger a.togglekinginfo').toggle(
		function(){ $(this).siblings("div").css({"display":"block"}); },
		function(){ $(this).siblings("div").css({"display": "none"}); }
	);
	if ($('.modeLeftArtikle, .modeCenterArtikle , .modeRightArtikle')[0]){
		$('.modeLeftArtikle, .modeCenterArtikle, .modeRightArtikle').equalHeight();
	}
	
	if ($('.modeFront, .modeFront2')[0]){
		$('.modeFront, .modeFront2').equalHeight();
	}
	if ($("#slider")[0]){
		$(window).bind("load",function(){
			$('#slider').slider({ 
			  steps: 100,
			  slide: function(e,ui) { 
				$("#sliderVal").text( ui.values ); 
			  }
			});
		});
	}
});

//<BB galleries>
function ajaxSwitchFullPhoto(itemid,position,next,gal,gdc){
    $.get(document.location.pathname,{p:'3',action:'switchFullPhoto', id:itemid, pos:position, next:next, gal:gal, gdc:gdc}, function(result){
    UpdateGeneralPhoto(result,gdc);
    });
}
    
function ajaxGetPhotos(position,max,category,gdc,gdcid){
    $.get(document.location.pathname,{p:'3',action:'getPhotos', pos:position, max:max, cat:category, gdc:gdc, gdcid:gdcid}, function(result){
    UpdateGeneralThumbnails(result, gdc);
    });
}

function ajaxSwitchGallery(itemid,position,next,gal,gdc){
    $.get(document.location.pathname,{p:'3',action:'switchGallery', id:itemid, pos:position, next:next, gal:gal, gdc:gdc}, function(result){
    UpdateGeneralFullPhoto(result, gdc);
    });
}

function ajaxSwitchCategory(category,gdc,gdcid){
    $.get(document.location.pathname,{p:'3',action:'switchCategory', cat:category, gdc:gdc, gdcid:gdcid}, function(result){
    UpdateGeneralGallery(result, gdc);
    });
}

function ajaxRatePhoto(id,gal,rate,gdc){
    $.get(document.location.pathname,{p:'3',action:'ratePhoto', id:id, gal:gal, rate:rate, gdc:gdc}, function(result){
    UpdateRateButtons(result,gdc);
    });
}

function ajaxSwitchFullVideo(itemid,position,next,gal,gdc){
    $.get(document.location.pathname,{p:'3',action:'switchFullVideo', id:itemid, pos:position, next:next, gal:gal, gdc:gdc}, function(result){
    UpdateGeneralPhoto(result,gdc);
    });
}

function ajaxGetVideos(position,max,category,gdc,gdcid){
    $.get(document.location.pathname,{p:'3',action:'getVideos', pos:position, max:max, cat:category, gdc:gdc, gdcid:gdcid}, function(result){
    UpdateGeneralThumbnails(result, gdc);
    });
}

function ajaxSwitchVideoGallery(itemid,position,next,gal,gdc){
    $.get(document.location.pathname,{p:'3',action:'switchVideoGallery', id:itemid, pos:position, next:next, gal:gal, gdc:gdc}, function(result){
    UpdateGeneralFullPhoto(result, gdc);
    });
}

function ajaxSwitchVideoCategory(category,gdc,gdcid){
    $.get(document.location.pathname,{p:'3',action:'switchVideoCategory', cat:category, gdc:gdc, gdcid:gdcid}, function(result){
    UpdateGeneralGallery(result, gdc);
    });
}

function ajaxRateVideo(id,gal,rate,gdc){
    $.get(document.location.pathname,{p:'3',action:'rateVideo', id:id, gal:gal, rate:rate, gdc:gdc}, function(result){
    UpdateRateButtons(result,gdc);
    });
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
    do {
    curleft += obj.offsetLeft;
    curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
    }
    return [curleft,curtop];
}

function setLeft(obj,lyr)
    {
    if (document.getElementById(lyr))
    {
    var coors = findPos(document.getElementById(obj));
    var x = document.getElementById(lyr);
    x.style.top = coors[1] + 'px';
    x.style.left = coors[0] + 'px';
    }
}

function setRight(obj,lyr){
    if (document.getElementById(lyr))
    {
    var coors = findPos(document.getElementById(obj));
    var x = document.getElementById(lyr);
    var y = document.getElementById(obj);
    x.style.top = coors[1] + 'px';
    var wid = y.style.width;

    x.style.left = coors[0] + parseInt(wid.replace(/px/,"")) - 76 + 'px';
    }
}

function popup(url,windowname,width,height,features)
    {
    width=(width)?width:screen.width/2;
    height=(height)?height:screen.height/2;
    var screenX = (screen.width/2 - width/2);
    var screenY = (screen.height/2 - height/2);
    var features= "width=" + width + ",height=" + height +",scrollbars=no,status=no";
    features += ",screenX=" + screenX + ",left=" + screenX;
    features += ",screenY=" + screenY + ",top=" + screenY;

    var mywin=window.open(url, windowname, features);
    if (mywin)
    mywin.focus();
    return mywin;
}
//</BB  galleries>


/* Billedbladet search */
function doSearch(txt)
{
        var text = '';
        if(null == txt)
	          text = document.getElementById('search_tb').value;
        else
	        text = txt;
        var searchPageURL = '/Search.aspx';
        if("" != text && "" != searchPageURL)
        {
          window.location.href = searchPageURL + "?search0=" + encodeURI(text);
        }
}  	  
//document.onkeydown = function (e)
//{
//  e=(window.event)? event:e;
//  var k=e.keyCode;
//  if(k == 13)
//  {
//      document.getElementById(document.getElementById('hide').value).click();
//  }
//}
var last_search_control_id = 'search0';
/* End Billedbladet search */

/* Billedbladet clock functions */
//function MakeHref(){
//      str = "";
//      if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
//      {
//        str = "<a href='javascript:void(0)' onclick='this.style.behavior=&amp;quot;url(#default#homepage)&amp;quot;;this.setHomePage('" + s_url + "&amp;quot;);'>";                                
//        str += s_text;
//        str += "&lt;/a&gt;";        
//      }
//      else if(document.getElementById)
//      {
//        //str = "&lt;a style='cursor:help' href='" + s_url + "' title='Make the Web Evangelism Guide your browser Start Page: drag this link onto the browser top-left Home graphic button' onClick='return false'&gt;" + s_text  + "&lt;/a&gt;";
//        str = "<a style='cursor:help' href='" + s_url + "' title='Make the Web Evangelism Guide your browser Start Page: drag this link onto the browser top-left Home graphic button' onClick='return false'>" + s_text  + "</a>";
//      }
//      else if (document.layers)
//      {
//        str = "&lt;span class='popup2' title=' Make the Guide your browser Start Page: - Go to Preferences in the Edit Menu. Choose Navigator from the list on the left. Click on the Use Current Page button.'&gt;Start page&lt;/span&gt;";
//      }
//      document.getElementById('bookMark').innerHTML = str;
//}
function MakeHref(){
  str = "";
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
  {
    str = "<a href='javascript:void(0)' onclick='this.style.behavior=&quot;url(#default#homepage)&quot;;this.setHomePage(&quot;" + s_url + "&quot;);'>";                                
    str += s_text;
    str += "</a>";        
  }
  else if(document.getElementById)
  {
    str = "<a style='cursor:help' href='" + s_url + "' title='Make the Web Evangelism Guide your browser Start Page: drag this link onto the browser top-left Home graphic button' onClick='return false'>" + s_text  + "</a>";    
  }
  else if (document.layers)
  {
    str = "<span class='popup2' title=' Make the Guide your browser Start Page: - Go to Preferences in the Edit Menu. Choose Navigator from the list on the left. Click on the Use Current Page button.'>Start page</span>";    
  }  
  var bookMark = $("#bookMark");
  bookMark.innerHTML = str;  
}
var clockID = 0;
function UpdateClock() {
    if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
    }

    var tDate = new Date();
//    document.getElementById('headerTimerPlace').innerHTML = "kl.  " + formatDate(tDate, " HH:mm") + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + formatDate(tDate, "dd.MM.yyyy");
document.getElementById('headerTimerPlace').innerHTML =  formatDate(tDate, "dd.MM.yyyy");
    MakeHref();
    clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
    clockID = setTimeout("UpdateClock()", 500);
}      
/* Billedbladet clock functions */     

function UpdateSmallPollResults(result)
{
    var list = document.getElementById('smallPollAnswersList');
    var div = document.getElementById('SmallPollLeftCorner');
    if (list !=null && div !=null && result != null  && result !="")
    {
        div.removeChild(list);
        div.innerHTML += result;
    }
}

function SetThankYouForVoting()
{
    var list = document.getElementById('smallPollAnswersList');
    var div = document.getElementById('SmallPollLeftCorner');
    if (div !=null && list !=null)
    {
        div.removeChild(list);
        if (lblThankYouForVoting != null)
        {
            var st = '<ul class="eventCalendar" id="smallPollAnswersList"><li>'+ lblThankYouForVoting
            + '</li><ul>';
            div.innerHTML += st;
        }
    }
}

function AnimateSmallPollBarFunction()
      {
        $('.smallpoll_boxLine').click(function(){
        var myWidth = $('.smallpoll_bar', this).attr('title') + '%';
        $('.smallpoll_bar', this).animate({width: myWidth}, 2000);
        //$('.bar', this).html(myWidth + '&#160;'); // adds some padding after the text, but doesn't effect the width;
        });
        $('.smallpoll_boxLine').click();
      }

function smallPollPreviewResults()
{
    var pollPreviewResultButton = document.getElementById('previewSmallPollLink');
    
    if (IsShowPreviewSmallPoll == true)
    {
        $('#smallPollAnswersList span.smallpoll_percent').css({"display":"none"});          
        //$('.bar').css({"width":"0"}); 
        $('#smallPollAnswersList div.smallpoll_boxLine').css({"display":"none"});  
                
        $('#smallPollAnswersList p.smallpoll_pointsParagraph').css({"display":"none"});  
          
        IsShowPreviewSmallPoll = false;
              
        if (pollPreviewResultButton != null)
        {
            if(lblSmallPollPreviewResult !=null && lblSmallPollHideResult!=null )
            {
                pollPreviewResultButton.innerHTML = lblSmallPollPreviewResult;
            }
        }
                                
    }
    else
    {
        $('#smallPollAnswersList span.smallpoll_percent').css({"display":"inline"});
        $('#smallPollAnswersList div.smallpoll_boxLine').css({"display":"block"});     
        $('#smallPollAnswersList p.smallpoll_pointsParagraph').css({"display":"block"});                
        
        IsShowPreviewSmallPoll = true;
        
        $('#smallPollAnswersList .smallpoll_boxLine').click(function(){
		var myWidth = $('.smallpoll_bar', this).attr('title') + '%';
		$('.smallpoll_bar', this).animate({width: myWidth}, 2000);
		//$('.bar', this).html(myWidth + '&nbsp;'); // adds some padding after the text, but doesn't effect the width;
		});
        $('#smallPollAnswersList .smallpoll_boxLine').click();	
        
        if (pollPreviewResultButton != null)
        {
            if(lblSmallPollPreviewResult !=null && lblSmallPollHideResult!=null )
            {
                pollPreviewResultButton.innerHTML = lblSmallPollHideResult;
            }
        }
        
    }

}

function getKey(evt,btnId) {
	if (document.getElementById('hide'))
		document.getElementById('hide').value = btnId;
	var ns6=document.getElementById&&!document.all;
     if (evt && ns6)
     typedKey=evt.which;
     else
     typedKey=event.keyCode;
     if (typedKey == 13) {
     if(document.all) {
     window.event.cancelBubble='true';
     window.event.returnValue = false;
     } else {
     evt.stopPropagation();
     evt.preventDefault();
     }

     document.getElementById(btnId).click();
     }
}

function SetProgress(id){
    $("#"+id).html('<img src="/images/progress.gif" style="padding-left:130px;padding-top:8px"/>');
} 
function UpdateGeneralPhoto(result,gdc){
    $("#fullPhoto"+gdc).html(result);
}

function UpdateGeneralThumbnails(result, gdc){
    $("#fotoGal"+gdc).html(result); 
    $(document).ready(function(){
    var d = 'fivePhotos' + gdc;
    var d2 = 'currentid' + gdc;

    $("#"+d+" img").css("border","");
    $("#small"+gdc+eval(d2)).css("border","2px solid black"); })
}

function UpdateGeneralFullPhoto(result,gdc){
    $("#fullPhoto"+gdc).html(result);
    $(document).ready(function(){
    var d = 'fivePhotos' + gdc;
    var d2 = "currentid" + gdc;

    $("#"+d+" img").css("border","");
    $("#small"+gdc+eval(d2)).css("border","2px solid black"); })
}

function UpdateGeneralGallery(result,gdc){
    $("#fotoItems"+gdc).html(result);
    $(document).ready(function(){
    var d = 'fivePhotos' + gdc;
    var d2 = "currentid" + gdc;

    $("#"+d+" img").css("border","");
    $("#small"+gdc+eval(d2)).css("border","2px solid black"); })
}


 function smallPollVote(pollid)
 {
    var radioObj;
    for (var i=0; i<document.forms.length; ++i)
    {
        radioObj = document.forms[i].elements['small_poll_answer'];
        if ( radioObj != null)
            break;
    }
    
    var answervalue = getRadioValue(radioObj);
    if (answervalue == "")
        return;        
    
    ajaxSmallPollVote(answervalue, pollid);
}

function ajaxSmallPollVote(voteid, pollid)
{
        SetThankYouForVoting();

        $.get(document.location.pathname,
        {p:'3',action:'smallPollVote', voteid:voteid, pollid:pollid},
        function(result)
        {
            UpdateSmallPollResults(result);
            AnimateSmallPollBarFunction();
        }
        );
}

function getRadioValue(radioObj)
{
    if(!radioObj)
    {
        return "";
    }
    var radioLength = radioObj.length;
    if(radioLength == undefined)
    {
        if(radioObj.checked)
        {
            return radioObj.value;
        }
        else
        {
            return "";
        }
    }
    for(var i = 0; i < radioLength; i++)
    {
        if(radioObj[i].checked)
        {
            return radioObj[i].value;
        }
    }
    return "";
}
function UpdateFullPhoto(itemid, result){
    $("#fullPhoto").html(result);
    $(document).ready(function(){
    $("img").css("border","");
    $("#small"+currentid).css("border","2px solid black");
    $("#small2"+currentid).css("border","2px solid black"); 
    $("#small3"+currentid).css("border","2px solid black"); })  
}

function UpdateThumbnails(position, max, result, gdc){
    $("#fotoGal"+gdc).html(result); 
    $(document).ready(function(){
    $("#small"+currentid).css("border","2px solid black");
    $("#small2"+currentid).css("border","2px solid black"); 
    $("#small3"+currentid).css("border","2px solid black"); })
}

function UpdateGallery(result){
    $("#fotoItems").html(result);
}

function UpdateBorder(){
    $(document).ready(function(){
    $("#small2"+currentid).css("border","2px solid black"); 
    $("#small3"+currentid).css("border","2px solid black"); })
}

function UpdateSearch(result){
    $("#gdc1").html(result);
    $(document).ready(function(){
    $("#small"+currentid).css("border","2px solid black");
    $("#small2"+currentid).css("border","2px solid black"); 
    $("#small3"+currentid).css("border","2px solid black"); })
}

function UpdatePhotoVideo(result){
    $("#galleries").html(result);
    $(document).ready(function(){
    $("#small"+currentid).css("border","2px solid black");
    $("#small2"+currentid).css("border","2px solid black"); 
    $("#small3"+currentid).css("border","2px solid black"); })
}

function UpdateFullVideo(itemid, result){
    $("#fullPhoto").html(result);
    $(document).ready(function(){
    $("img").css("border","");
    $("#small"+currentid).css("border","2px solid black");
    $("#small2"+currentid).css("border","2px solid black"); 
    $("#small3"+currentid).css("border","2px solid black"); })  
}

function UpdateRateButton(result){
    $("#rateButtons").html(result);
}

function UpdateRateButtons(result,gdc){
    $("#rateButtons"+gdc).html(result);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}