function getPosition(obj){ 
	var left=0, top=0; 
	while(obj){ 
		left += obj.offsetLeft;
  		top += obj.offsetTop;
  		if(obj.style.borderTopWidth != ''){
 			top += parseInt(obj.style.borderTopWidth);
		}
		if(obj.style.borderLeftWidth != ''){ 
			left += parseInt(obj.style.borderLeftWidth); 
		}
		obj = obj.offsetParent; 
	}
 	return {left: left, top: top};
}
	
function initGalleries() {
	$('.gallery').galleryScroll({
		btPrev: 'a.prev',   
		btNext: 'a.next',
		holderList: 'div.gallery-holder',
		scrollElParent: 'div.gallery-holder ul',
		scrollEl: 'div.gallery-holder ul li',
		slideNum: '.switcher',
		duration : 500,
		step: false,
		circleSlide: true,
		disableClass: 'disable',
		funcOnclick: null,
		autoSlide: 4000 
	});
}

function initCallMeButtons(){
	$("a.click-callme").click(function(){
		var callme = $("div.light-callme");
		
		if($(this).hasClass('inline')){
			//call-me inline
			var pos = getPosition(document.getElementById('callme'));
			callme.addClass('callme-inline').css({left: (pos.left - 159) + 'px', top: (pos.top + 1) + 'px'}).show();
		} else {
			//call-me popup
			callme.css({left: ($(window).width() / 2 - callme.width() / 2) + 'px', top: ($(window).height() / 2 - callme.height() / 2 + $(window).scrollTop()) + 'px'}).show();
			$("div.light-box-holder").show();
		}
		$('select', callme).customSelect();
		return false;
	});
	$('div.light-box').css("height", $(document).height() + 'px').click(function(){
		$(".hide").css("display","none");
	});
	$("a.close").click(function(){
		$(".hide").css("display","none");
		return false;
	});
	
//	$(".btn-callme-submit").click(function(){
//		
//		return true;
//	});
}

function callmeAfterSubmit() {
    var callme = $("div.light-callme");
    var thank = $("div.thank");
    callme.hide();
    if(callme.hasClass('callme-inline')){
	    //inline
	    var pos = getPosition(document.getElementById('callme'));
	    thank.addClass('thank-inline').css({left: (pos.left - 159) + 'px', top: (pos.top + 1) + 'px'}).show();
	    
    } else {
	    //popup
	    thank.css({left: ($(window).width() / 2 - thank.width() / 2) + 'px', top: ($(window).height() / 2 - thank.height() / 2 + $(window).scrollTop()) + 'px'}).show();
	    $("div.light-box-holder").show();
    }
}


function initAccordions() {
		$(document).ready(function(){
	        $('ul.accordion').accordion({
		        active: false, 
		        //active: ".selected",
		        autoHeight: false,
		        header: ".opener",
		        collapsible: true,
		        event: "click"
	        });

	        $('ul.accordion1').accordion({
	            active: false, 
		        autoHeight: false,
		        header: ".opener1",
		        collapsible: true,
		        //fillSpace: true,
		        event: "click"
	        });
	        
//	         $('ul.sidebar-menu').accordion({
//	            active: ".selected",
//		        autoHeight: false,
//		        collapsible: true//,
//		        //header: ".show"
//	        });
        });
		
		$('ul.accordion li a.opener').bind('click', function(e){
			if(e.target.tagName == 'A' || e.target.tagName == 'a'){
				$(e.target).parents('li').find('ul').hide();
				document.location = e.target.href;
			} else {
				if(!$(e.target).parents('li').find('ul').length){
					document.location = $(e.target).parents('a').attr('href');
				}
			}
			return false;
		});
		
		$(".accordion li a").textShadow(); //??
}

$(document).ready(function(){
						   
	initPage();
	initGalleries();
	initAccordions();
	initCallMeButtons();
	
});


function ClearDefault(obj, defaultValue)
{
    if ($(obj).val() == defaultValue)
        $(obj).val('');
}

function AddDefault(obj, defaultValue)
{
    if ($(obj).val() == '')
        $(obj).val(defaultValue);
}
