
function loginPrep() {
	var p = $('#signinPassword').val();
	$('#signinPassword').val(portal_sha1(p));
	return true;
}

function initSidebar(){
	$("#sidenav .sectbody").hide();
	$("#sidenav td.expandcollapse").click(
		function(){
			if ($(this).parents(".secthead").children(".sectbody").css("display") == "none") {
				$("#sidenav .sectbody").slideUp(fxspeed / 2);
				$("#sidenav .expandcollapse").each(function(){if($(this).html()!="") $(this).html("[ + ]");});
				$(this).html("[ &#8211; ]").parents(".secthead").children(".sectbody").slideDown(fxspeed);
			}
			else {
				$(this).parents(".secthead").children(".sectbody").slideUp(fxspeed);
				if($(this).html()!="") $(this).html("[ + ]");
			}
	});
	$("#sectheadactive .expandcollapse").click();

	$("#sidenav .secthead").hover(
		function(){$(this).css({backgroundColor: "#ff8040", color: "#fff"})},
		function(){if($(this).attr("id")!="sectheadactive") $(this).css({backgroundColor: "#7B2E40", color: "#fff"})}
	);
}

function initTopNavigation(){
	$("#topnav td.topnavcell").hover(
		function(){$(this).css({backgroundColor: "#ff8040", color: "#fff", borderTop:"1px solid #fff"})
			.children("a").css({backgroundColor: "#ff8040", color: "#fff"})},
		function(){$(this).css({backgroundColor: "#7B2E40", color: "#fff", borderTop:"1px solid #7B2E40"})
			.children("a").css({backgroundColor: "#7B2E40", color: "#fff"})}
	);	
}

function initViewerSidebar(){
	
	  $("body").append("<div id='viewerSidebarCont'><table><tr><td></td><td id='viewerSidebarBg'></td></tr></table></div>");
      $("#viewerSidebarBg").css({
        width: "58px", height:"130px", backgroundColor: "#7B2E40", color: "#fff", borderRight:"1px solid #666",
		padding:"10px 0 10px 4px", position:"absolute", zIndex:"900", top:"11px", right:"0",
        overflow: "hidden"
      }).show();

	  $("body").append("<div id='viewerSidebarExit'>Nazad</div>");
      $("#viewerSidebarExit").css({
        width: "68px", backgroundColor: "#ff8040", color: "#fff", border:"1px solid #fff", borderRight:"1px solid #ff8040",
		padding:"10px 0 10px 10px", position:"absolute", zIndex:"901", top:"21px", right:"0",
		fontSize:"14px", fontWeight:"bold", cursor:"pointer"
      }).show().hover(function(){$(this).css({width:"89px"});}, function(){$(this).css({width:"68px"});})
	  .click(function(){window.location.href="katalog.php";});

	  $("body").append("<div id='viewerSidebarAd'>Reklama</div>");
      $("#viewerSidebarAd").css({
        width: "74px", backgroundColor: "#ff8040", color: "#fff", border:"1px solid #fff", borderRight:"1px solid #ff8040",
		padding:"10px 0 10px 10px", position:"absolute", zIndex:"901", top:"64px", right:"0",
		fontSize:"14px", fontWeight:"bold", cursor:"pointer"
      }).show().hover(function(){$(this).css({width:"114px"}).text("Vaša reklama");}, function(){$(this).css({width:"74px"}).text("Reklama");})
	  .click(function(){window.location.href="../rest/marketing.php";});
	
}

var fxspeed = 300;

$(document).ready(function () {

	$('input[type="text"]:first').focus();
	
	initSidebar();
	initTopNavigation();
	
	if(document.getElementById("g1")!=null) initViewerSidebar();
	
	if ($.datepicker) {
		$.datepicker.setDefaults({
   			firstDay: 1,
   			dateFormat: 'dd.mm.yy',
   			changeYear: true,
   			yearRange: '1900:2050',
			changeMonth: true,
			gotoCurrent: true });
			
		$('.inputDate').datepicker();
	}
	
	if ($.fn.s3Capcha) {
		$('#capcha').s3Capcha();
	}
	
	$('.messageBoxes').click(function() { $(this).hide(); });

});


