$(document).ready(function(){
	ieHover('#menu li');
	if(typeof($().galleryScroll) == 'function'){
		$('#gallery').galleryScroll({
			btPrev: 'a.link-prev',
			btNext: 'a.link-next',
			holderList: 'div',
			scrollElParent: 'ul',
			scrollEl: 'li',
			slideNum: false,
			duration : 1000,
			step: false,
			circleSlide: true,
			disableClass: 'disable',
			funcOnclick: null
		});
	}
	initSlider();
});
function initSlider(){
	$('.period').each(function(){
		var _a = -1;
		var _list = $(this).find('ul li');
		var text_box = $(this).find('.info-text');
		_list.each(function(_i){
			if($(this).hasClass('active')) _a = _i;
			this.onclick = function(){
				changeEl(_i, true);
				return false;
			}
			this.onmouseover = function(){
				if(_a != _i){
					_list.eq(_a).removeClass('active').find('div').hide();
					$(this).addClass('active');
					if(text_box.length) text_box.html($(this).find('div').html());
					else $(this).find('div').show();
				}
			}
			this.onmouseout = function(){
				if(_a != _i){
					$(this).removeClass('active').find('div').hide();
					_list.eq(_a).addClass('active');
					if(text_box.length) text_box.html(_list.eq(_a).find('div').html());
					else _list.eq(_a).find('div').show();
				}
			}
		});
		if(_a != -1){
			if(text_box.length) text_box.html(_list.eq(_a).find('div').html());
			else _list.eq(_a).find('div').show();
		}
		$(this).find('.back').click(function(){
			if(_a > 5)	changeEl(_a - 5, false);
			else if(_a > 0)	changeEl(_a - 1, false);
			return false;
		});
		$(this).find('.next').click(function(){
			if(_a < _list.length - 5) changeEl(_a + 5, false);
			else if(_a < _list.length - 1) changeEl(_a + 1, false);
			return false;
		});
		function changeEl(_ind, bRedirect){
			_a = _ind;
			if(bRedirect)
			{				
				if (document.getElementById(_a+1) != null)
					window.location.href= document.getElementById(_a+1);
			}
			else if(_ind != _a){
				_list.eq(_a).removeClass('active').find('div').hide();
				_list.eq(_ind).addClass('active');
				if(text_box.length) text_box.html(_list.eq(_ind).find('div').html());
				else _list.eq(_ind).find('div').show();
				_a = _ind;
			}		
		}
	});
}
function ieHover(h_list) {
	if ($.browser.msie && $.browser.version < 7) {
		$(h_list).hover(function() {
			$(this).addClass('hover');
			if($(this).children('div').length) hideSelectBoxes($(this).children('div').eq(0));
		}, function() {
			$(this).removeClass('hover');
			if($(this).children('div').length) showSelectBoxes($(this).children('div').eq(0));
		});
	}
}
function hideSelectBoxes(object) {
	if ($.browser.msie && $.browser.version < 7) {
		var selects_list = $('select');
		object.each(function() {
			var _el = $(this);
			var t = _el.offset().top;
			var l = _el.offset().left;
			var w = _el.outerWidth();
			var h = _el.outerHeight();
			var el_selects = [];
			selects_list.filter(':visible').not(_el.find('select')).each(function(){
				var _select = $(this);
				var s_t = _select.offset().top;
				var s_l = _select.offset().left;
				var s_w = _select.outerWidth();
				var s_h = _select.outerHeight();
				var _ver = false, _hor = false;
				if((t - s_t > 0) ? (t - s_t < s_h) : (t - s_t + h > 0)) _ver = true;
				if((l - s_l > 0) ? (l - s_l < s_w) : (l - s_l + w > 0)) _hor = true;
				if(_ver && _hor) {
					_select.css('visibility', 'hidden');
					el_selects.push(this);
				}
			});
			this.sboxes = el_selects;
		});
	}
}
function showSelectBoxes(object) {
	if ($.browser.msie && $.browser.version < 7) {
		object.each(function() {
			if(this.sboxes.length > 0) {
				$(this.sboxes).css('visibility','visible');
			}
		});
	}	
}

function ToggleArticleDisplay(type)
{
    var full = document.getElementById("fullText");
    var paged = document.getElementById("pagedText");
    var fulllink = document.getElementById("FullLink");
    var pagedlink = document.getElementById("PagedLink");
    
    if (type == 1)
    {
        full.style.display = 'inline';
        paged.style.display = 'none';
        fulllink.style.display = 'none';
        pagedlink.style.display = 'block';
    }
    else
    {
        full.style.display = 'none';
        paged.style.display = 'inline';
        pagedlink.style.display = 'none';
        fulllink.style.display = 'block';        
    }     
}


 function submitForm()
 {
 	var submitForm = document.createElement("FORM");
	submitForm.Id = "searchbox_012637101302161472059:xhjhbftt5zc";
	document.body.appendChild(submitForm);
	submitForm.method = "GET";
	var newElement = document.getElementById("googleSearch");
	submitForm.appendChild(newElement);
	submitForm.action= "http://birth.com.au/GoogleSearchResults.aspx";
	submitForm.submit();
 }     
 
 function submitStreamsendRequest(metod, url)
 {
    document.forms[0].method = method;
    document.forms[0].action = url;
    document.forms[0].submit();
 }
 
 function fbs_click() 
 {
    u=location.href;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
 }
 
 function openBrWindow(theURL,winName,features) {
	winName = window.open(theURL,winName,features);
	winName.focus()
}

function ShowHelp(div, title, desc)
{
	div = document.getElementById(div);
	div.style.display = 'inline';
	div.style.position = 'absolute';
	div.style.width = '176';
	div.style.color = '#000000';
	div.style.backgroundColor = '#FAFAFA';
	div.style.border = 'solid 1px #CCCCCC';
	div.innerHTML = '<div>' + desc + '</div>';
}

function HideHelp(div)
{
	div = document.getElementById(div);
	div.style.display = 'none';
}

function windowOpen(sURL, sTitle, sParams) {
 var s = sURL.replace(/-/,'%2D');
 var st = sTitle.replace(/-/,'_');
 var sti = st.replace('.', '_');
 window.open(s, sti, sParams)
}

