$(function(){
	//slider
	$("#featureActivities ul").jcarousel({
		scroll: 3
	});
	$("#featureExpertise ul").jcarousel({
		scroll: 5
	});
    

	//Tabs
//	$('#tabs li').click(function(){
//		var ul = $(this).parent();
//		ul.find('li').removeClass('current');
//		ul.nextAll('div:visible').hide('fast');
//		$(this).addClass('current');
//		$('#' + this.id + '_box').fadeIn('fast');
//	}).find('a').click(function(e){
//		e.preventDefault();
//	}).focus(function(){
//		this.blur();
//	});
$('#tabs_last li').click(function(){
		var ul = $(this).parent();
		ul.find('li').removeClass('current');
		ul.nextAll('div:visible').hide('fast');
		$(this).addClass('current');
		$('#' + this.id + '_box').fadeIn('fast');
	}).find('a').click(function(e){
		e.preventDefault();
	}).focus(function(){
		this.blur();
	});
	//combobox
	$('.combox').combobox({
		comboboxContainerClass: "comboboxContainer",
		comboboxValueContentContainerClass: "comboboxValueContainer",
		comboboxValueContentClass: "comboboxValueContent",
		comboboxDropDownClass: "comboboxDropDownContainer",
		comboboxDropDownButtonClass: "comboboxDropDownButton",
		comboboxDropDownItemClass: "comboboxItem",
		comboboxDropDownItemHoverClass: "comboboxItemHover",
		comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader",
		comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer"
	});

	//fix IE png bug
	if ($.browser.msie && parseInt($.browser.version) < 7) {
		$('.fixPng').each(function(){
			var w = this.width;
			var h = this.height;
			$(this).css({
				'width': w,
				'height': 0,
				'paddingTop': h
			});
			this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "')";
		});
	}

	//toggle menu
	$('.toggleBlock .toggle h2').click(function(){
		$(this).next().toggle('fast', function(){
			$(this).parent().toggleClass('close');
		});
	});
	
	//toggle menu
	$('#relatedActivities .toggle h2').click(function(){
		$(this).next().toggle('fast', function(){
			$(this).parent().toggleClass('close');
		});
	});
	//adv
	var count = 0;
	$("#adv").click(function(){
		$("#advBox").slideToggle('fast', function(){
				if(count < 2)
				$('#advBox .comboxtoggle').combobox({
				comboboxContainerClass: "comboboxContainer",
				comboboxValueContentContainerClass: "comboboxValueContainer",
				comboboxValueContentClass: "comboboxValueContent",
				comboboxDropDownClass: "comboboxDropDownContainer",
				comboboxDropDownButtonClass: "comboboxDropDownButton",
				comboboxDropDownItemClass: "comboboxItem",
				comboboxDropDownItemHoverClass: "comboboxItemHover",
				comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader",
				comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer"
				});	
				$("#adv").toggleClass('advCurrent');
		});
		count++;
		return false;
	});
	//postComment
	$('#post').click(function(){
		$('#postComment').toggle('fast', function(){
			$('#post').toggleClass('postCurrent');
		});
		return false;
	});

	//preview
	$('#previewWrapper a').click(function(){
		var newSrc = this.href;
		$(this).parent().siblings('li').removeClass('current').end().addClass('current');
		$('#preview').fadeOut('fast', function(){
			$('#preview').attr('src', newSrc).fadeIn('fast');
		});
		return false;
	}).focus(function(){
		this.blur();
	});
});

/* BookMark */
function bookmarksite(title)
{    
    url = window.location.href
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print)
    { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href',url);
        elem.setAttribute('title',title);
        elem.setAttribute('rel','sidebar');
        elem.click();
    }
    else if(document.all)// ie
        window.external.AddFavorite(url, title);
}

/*Paging*/
function ExchangePager()
{
        var tbl=document.getElementById('gvActivities');
        var pager=tbl.rows[tbl.rows.length-1].cells[0];
        var span=document.getElementById('pnlPager');
        if(pager==null) return;
        if(span==null) return;
        tbls=pager.getElementsByTagName('table');
        var pages='';
        for(var i=0;i<tbls[0].rows[0].cells.length;i++)
        {
            if(i==tbls[0].rows[0].cells.length-1)
                pages+=tbls[0].rows[0].cells[i].innerHTML;
            else
                pages+=tbls[0].rows[0].cells[i].innerHTML+' | ';
        }
        var spanpager=document.getElementById('spanPager');
        spanpager.innerHTML=pages;
        pager.style.display='none';
}

function ExchangePagerSettings(gridName, pagerName, pagerSpanName)
// gridName = the grid control name
// pagerName = the pager panel name
// pagerSpanName = the span that contains the page count

{
        var tbl=document.getElementById(gridName);
        var pager=tbl.rows[tbl.rows.length-1].cells[0];
        var span=document.getElementById(pagerName);
        if(pager==null) return;
        if(span==null) return;
        tbls=pager.getElementsByTagName('table');
        var pages='';
        for(var i=0;i<tbls[0].rows[0].cells.length;i++)
        {
            if(i==tbls[0].rows[0].cells.length-1)
                pages+=tbls[0].rows[0].cells[i].innerHTML;
            else
                pages+=tbls[0].rows[0].cells[i].innerHTML+' | ';
        }
        var spanpager=document.getElementById(pageSpanName);
        spanpager.innerHTML=pages;
        pager.style.display='none';
}

/* Comment */
function lbtnPost_Onclick()
{ 
    document.getElementById('ComHide').style.display = '';
    document.getElementById('txtComments').focus();
} 

function lbtnPost_Onclick1()
{ 
    document.getElementById('ComHide').style.display = '';
    document.getElementById('txtCaptcha').focus();
}

/* In PRogress */
function SetInProgressImagePosition()
{
    try
    {
        var div=document.getElementById('divProgress');
        var tp=document.body.scrollTop;
        div.style.top=300+document.body.scrollTop;
        div.style.left=500;
    }
    catch(e)
    {
        alert(e.message);
    }
}

// Used by the Control\Wigdets\Loading custom control...

function SetInProgressPosition(ctlname,divwidth)
{
    try
    {
        var div=document.getElementById(ctlname);        
        div.style.top=300+document.documentElement.scrollTop + 'px';
        try
        {
        // to handle IE issues
        div.style.left=((document.documentElement.clientWidth/2)-(divwidth/2)) + 'px';
        }
        catch(e)
        {
        div.style.left=((window.innerWidth/2)-(divwidth/2)) + 'px';
        }
    }
    catch(e)
    {
        alert('SetInProgressPosition ' + e.message);
    }
}

function RoundCorners(idtag)
{
    $('#" + idtag+ "').corner('round 8px');
}

function SetInProgressPositionPercent(ctlname,divwidth)
{
    try
    {
        var div=document.getElementById(ctlname);        
        div.style.top=300+document.documentElement.scrollTop + 'px';
        try
        {
        // to handle IE issues
        //div.style.left=((document.documentElement.clientWidth/2)-(divwidth/2)) + 'px';
        div.style.left=((100-divwidth)/2) + '%';
        }
        catch(e)
        {
        //div.style.left=((window.innerWidth/2)-(divwidth/2)) + 'px';
        div.style.left=((100-divwidth)/2) + '%';
        }
    }
    catch(e)
    {
        alert('SetInProgressPositionPercent ' + e.message);
    }
}

/* Page top */
function pagetop()
{
    window.top.scrollTo(0,550);
}
function pagetopAct()
{
    window.top.scrollTo(0,450);
}
function pagetopActCat()
{
    window.top.scrollTo(0,250);
}
function pagetopBlogs()
{
    window.top.scrollTo(0,530);
}
function pagetop(yLoc)
{
    window.top.scrollTo(0,yLoc);
}

// gvName is the name of the GridView
// pnlPagerName is the name of the panel that contains the pager
// spanPagerName is the span to load the page counts into
function UpdatePageCountsInPager(gvName, pnlPagerName, spanPagerName)
{

 var tbl=document.getElementById(gvName);
 if (tbl.rows.length>0)
 var pager=tbl.rows[tbl.rows.length-1].cells[0];
 var span=document.getElementById(pnlPagerName);
 if(pager==null) return;
 if(span==null) return;
 tbls=pager.getElementsByTagName('table');
 var pages='';
 for(var i=0;i<tbls[0].rows[0].cells.length;i++)
 {
 if(i==tbls[0].rows[0].cells.length-1)
 pages+=tbls[0].rows[0].cells[i].innerHTML;
 else
 pages+=tbls[0].rows[0].cells[i].innerHTML+' | ';
 }
 var spanpager=document.getElementById(spanPagerName);
 spanpager.innerHTML=pages;
 pager.style.display='none';
}