
function getBackUrlParam()
{
    var s = document.location.href;
    
    if(s.indexOf('&#')!=-1)
    {
        s = s.replace('&#','&&');
    }
    return "backurl="+encodeURIComponent(s);
}

function showGalleryPhotoPreview(sender)
{
  
    var previewUrl = sender.getAttribute('previewUrl');
    var desc = sender.getAttribute('desc');
    
    var html = "<div style='width:310px;padding-top:5px;padding-bottom:5px' align='center'><img src='"+previewUrl+"'>";
    html += "<div style='width:100%;text-align:center;padding-top:6px;color:#555555'>"+desc+"</div>";    
    html += "</div>";
    
    Tip(html, CLICKCLOSE, true, ABOVE, false, LEFT, false, FADEIN, 300, WIDTH, 310, BGCOLOR,'whitesmoke', BORDERSTYLE, 'solid', BORDERCOLOR, '#bbbbbb');
}

function showGalleryPhotoPreview14(sender)
{
  
    var previewUrl = sender.getAttribute('previewUrl');
    var desc = sender.getAttribute('desc');
    
    var html = "<div style='width:400px;padding-top:5px;padding-bottom:5px' align='center'><img style='width: 400px' src='"+previewUrl+"'>";
    html += "<div style='width:400px;text-align:center;padding-top:6px;color:#555555'>"+desc+"</div>";    
    html += "</div>";
    
    Tip(html, CLICKCLOSE, true, ABOVE, false, LEFT, false, FADEIN, 300, WIDTH, 400, BGCOLOR,'whitesmoke', BORDERSTYLE, 'solid', BORDERCOLOR, '#bbbbbb');
}

function openGalleryPhotoDetails(sender)
{
    var photoId = sender.getAttribute('photoId');
    openPopupWindow('/portal/galeria/podglad.aspx?ID='+photoId,'preview_'+photoId,620,690,null,null);
}

function openPopupWindow(url,name,width,height,posX,posY)
{
    var sFeatures = 'status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=0,width='+width+',height='+height;
    
    if(posX==null)
    {
        var leftPos = (screen.width - width) / 2;
        var topPos = (screen.height - height) / 2;
       
        sFeatures += ',left='+leftPos+',top='+topPos;
    }
    else
        sFeatures += ',left='+posX+',top='+posY;
        
    return window.open(url,name,sFeatures,true);
}

function tellFriend()
{
    var url = encodeURIComponent(document.location.href);
    //alert('Przepraszamy, ale funkcja jest chwilowo niedostepna..');
    openPopupWindow('/portal/inne/PowiadomZnajomego.aspx?Url='+url,'preview',500,290,null,null);
    
}


var PROFILE_DEFAULT_TAB = 0;

var homeo =  {

	globals: {},

	start: function () {

		this.all();
		this.tabs.homepage();
        this.tabs.profile();
		this.userMenu();
		this.slider();
		this.slide_box();
		this.dynamic.user_registration();
        this.dynamic.equal_column_height('#community .users_list li .block');
        this.dynamic.equal_column_height('#profile_logged_page #gallery_edit .photos_list .gallery .list li div');

        //this.ie6.pngFix();

	},

	/* Functions used in whole website */
	all: function () {

		// Printing when specific "print link" exists
		$("a.print").bind("click", function(){
			window.print();
			return false;
		});

        $('#bottomMenu li:not(:last)').after('| ');

        var rows = $('table.calendar_day').find('tbody tr');
        rows.filter(':odd').find('td').addClass('even');
        
        $('.profile_tab_box h3:first').css('margin-top', '0');
	},
	
	dynamic: {
		
		user_registration: function() {
			var form = $('#registration_form');
			var inputs = form.find('.reg_select input');
			var divs = form.find('.reg_doctor, .reg_user');
			divs.hide();
			
			inputs.click(function(e){
				id = $(this).attr('id');
				
				var el = '.'+id;
				
				divs.hide();
				form.find(el).show();

				e.preventDefault;
			}).eq(0).click();
		},
		
		equal_column_height: function (group) {
			var tallest;
			tallest = 0;
			$(group).each(function(){
				thisHeight = $(this).height();
				if (thisHeight > tallest) {
					tallest = thisHeight;
				}
			});
			$(group).css('height', tallest);
		}
	},

	tabs: {
        homepage: function(){
            var tabContainers = $('.home_tab_box > div');
            var buttons = $('.home_tab_box ul.tab_nav a');
            buttons.click(function(e){
                tabContainers.hide().filter(this.hash).show();
                buttons.removeClass('active');
                $(this).addClass('active');
                e.preventDefault();
            }).filter(':first').click();
        },

        profile: function(){
            var tabContainers = $('.profile_sections li div');
            var buttons = $('.profile_tab_box ul.tab_nav a').not('.back_to_profile');
            buttons.click(function(e){
                tabContainers.hide().filter(this.hash).show();
                buttons.removeClass('active');
                $(this).addClass('active');
                var aa = $(this).attr('title');
                e.preventDefault();
            }).eq(PROFILE_DEFAULT_TAB).click();
        }
	},

	userMenu: function() {
        var menu = $('#userMenu');
        var containers = $('#loginContainer, #registerContainer');
        containers.hide();
        var button = $('a#userLogin');
        
        button.click(function(e){
            var el = (this.hash).substr(1);
            //menu.toggleClass('active');
            menu.toggleClass('active').find(this.hash).toggle().end().find('div.cont').not(this.hash).hide();
            e.preventDefault();
        });
	},

	slider: function(){
		$('#promo_slideshow').wslide({
			width: 663,
			height: 251,
			horiz: true,
			duration: 2000
			});
	},

    slide_box: function(){
        var slideboxes = $('.subpage #sidebar .slide_box');
        var sw = slideboxes.find('.head .opt a');
        var contents = slideboxes.find('.content');

        contents.hide();
        
        sw.click(function(e){
            $(this).toggleClass('active');
            sw.not(this).removeClass('active');
            slideboxes.filter(this.hash).find('.content').toggle();
            e.preventDefault();
        });
        
        sw.eq(0).click();
        sw.eq(1).click();
        sw.eq(2).click();
    },
    
	/* Functions used in IE6 to fix common issues */
	ie6: {
		// PNG transparency for Windows IE 5.5 & 6
		pngFix: function () {
            //if ($.browser.msie && $.browser.version == 6) {
            if ($.browser.msie) {
                DD_belatedPNG.fix(".png_bg");
                DD_belatedPNG.fix("#mainMenu a");
                DD_belatedPNG.fix("#section .promo_box .wslide-menu");
                DD_belatedPNG.fix("#section .promo_box .wslide-menu a");
                DD_belatedPNG.fix("#bottomMenu");
            }
		}
	},

	/* Functions used in IE7 to fix common issues */
	ie7: {
	}

}

$(function() {
	homeo.start();
});

