$(function() {
    /*$(".boxthumb").jCarouselLite({
		visible: 4,
        btnNext: ".nextgal",
        btnPrev: ".prevgal",
		speed: 500,
		circular: false,
		hideArrow: true,
		mouseWheel: true,
		easing: "easein"
    });*/
	if( $('.lightbox').length > 0 )
		$(".lightbox").lightbox();
	
	$('img').each(function(){
		if($(this).attr('src') == ""){
			$(this).remove();
		}
	})
});
function closeform(idclass){
	$('.'+idclass).fadeOut('fast', function(){
		$(this).remove();
		$('#background').remove();
	}); 
}
function replyComment(e, type){
	parentId = $(e).parent().attr('value');
	if( type == 'edit' ){
		value = $(e).parent().find('p').html();
		value = str_replace('<br>', '', value);
		hiddenForm = '<input type="hidden" name="action" value="updateguest" /><input type="hidden" name="parent_reply" value="'+parentId+'" />';
	}
	else{
		value = '';
		hiddenForm = '<input type="hidden" name="action" value="addadmin" /><input type="hidden" name="caseadmin" value="1" /><input type="hidden" name="parent_reply" value="'+parentId+'" />';	
	}
	form = '<div id="background"></div><div class="replayform">'+
				'<div class="closemail"><a href="javascript:void(0);" onclick="closeform(\'replayform\')">Close</a></div>'+
				'<form id="mailform" method="post">'+
				'<p>Reply comment<br/><textarea name="comment" rows="10" cols="50">'+value+'</textarea></p>'+
				hiddenForm+
				'<p><input type="submit" value="Add replay" /></p></form>'+
			'</div>';
	Topoffset = topoffset();
	$('body').append(form);
	$('#background').css({opacity:0.9, height:getPageSize()[1]})
	$(".replayform").css({top: Topoffset + 100, left: (screen.width - 450)/2}).fadeIn('fast');
}
function viewform(id){
	$(id).slideDown('slow');	
}
function cancelform(id, idform){
	$(idform)[0].reset()
	$(id).slideUp('slow');
}
function deleteComment(e){
	idDel = $(e).parent().attr('value');
	conf = confirm('are u sure want to delete this one?');
	if( conf == true ){
		form = '<form id="delform" method="post"><input type="hidden" name="action" value="deleteguest" /><input type="hidden" name="parent_reply" value="'+idDel+'" /></form>';
		$('body').append(form);
		$('#delform')[0].submit();
	}
	else{
		return false;
	}
}
function topoffset(){
	var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body;
	var ie=document.all && !window.opera;
	var dom=document.getElementById;
	var scroll_top=(ie)? standardbody.scrollTop : window.pageYOffset;
	return scroll_top;
}
function getPageSize(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) { // all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}


	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}
function str_replace (search, replace, subject, count) {
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}
