var xmlhttp;
var clickNumber = 1;
function contact(){
    xmlhttp=GetXmlHttpObject();
    var url="/control/contactdetails.php";
    loadng = 'contact';
    document.getElementById("preloading").innerHTML = '<div id="load"></div>';
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}
function sectionID(rs){
    xmlhttp=GetXmlHttpObject();
    var url="/control/section.php?id="+rs;
    loadng = 'section';
    document.getElementById("loadthis").innerHTML = '<div id="loadingloader"></div>';
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    $('.classsection').removeClass('currentsection');
    $('.section'+rs).addClass('currentsection');
	clickNumber=1;
	$(".ReferentiesContener").css("marginLeft","0");
}

function newsrecords(id){
    xmlhttp=GetXmlHttpObject();
    var url="/control/newsrecords.php?recordid="+id.id+"&year="+id.name;
    loadng = 'newsrecords';
    document.getElementById("loadthis").innerHTML = '<div id="loadingloader"></div>';
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);

}

function year(yr){
    xmlhttp=GetXmlHttpObject();
    var url="/control/year.php?id="+yr;
    loadng = 'monthset';
    document.getElementById("loading").innerHTML = '<div id="load"></div>';
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    $('.accordionButton').removeClass('currentsection');
    $('.adthis'+yr).addClass('currentsection');
    clickNumber=1;
    $(".ReferentiesContent").css("marginLeft","0");
}

function backtoyear(year){
    xmlhttp=GetXmlHttpObject();
    var url="/control/year.php?id="+year;
    loadng = 'yearback';
    document.getElementById("loading").innerHTML = '<div id="load"></div>';
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function newsdetails(year){
    xmlhttp=GetXmlHttpObject();
    var url="/control/newsdetails.php?id="+year;
    loadng = 'newsdetails';
    document.getElementById("loading").innerHTML = '<div id="load"></div>';
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function basemonth(rs){
    xmlhttp=GetXmlHttpObject();
    var url="/control/newsdetails.php?id="+rs;
    loadng = 'newsdetails';
    document.getElementById("loading").innerHTML = '<div id="load"></div>';
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function workers(id){
    xmlhttp=GetXmlHttpObject();
    var url="/control/medewerkers.php?id="+id;
    loadng = 'worker';
    document.getElementById("loading").innerHTML = '<div id="load"></div>';
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function change(str){
    xmlhttp=GetXmlHttpObject();
    id=str;
    var url="/scenarioplanner/recordset.php?id="+str;
    loadng = 'recordset';
    document.getElementById("loading").innerHTML = '<div id="load"></div>';
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);   
}

function month(m){
    xmlhttp=GetXmlHttpObject();
    var url="/control/month.php?id="+m;
    loadng = 'monthset';
    document.getElementById("loading").innerHTML = '<div id="load"></div>';
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function backtocontact(){
    xmlhttp=GetXmlHttpObject();
    var url="/control/contact.php";
    loadng = 'contactlist';
    document.getElementById("preloading").innerHTML = '<div id="load"></div>';
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function viewImg(img){
    xmlhttp=GetXmlHttpObject();
    var url="/control/viewimage.php?imgid="+img.id+"&name="+img.name;
    loadng = 'changeimage';
    document.getElementById("loading").innerHTML = '<div id="load"></div>';
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);   
}

function stateChanged(){
    if (xmlhttp.readyState==4){
            document.getElementById("change_div_"+loadng).innerHTML=xmlhttp.responseText;
            document.getElementById("loading").innerHTML = '';
            document.getElementById("loadthis").innerHTML = '';
            if(loadng == 'contact'){
                document.getElementById("preloading").innerHTML = '';
                 $("#commentForm").validate();
            }
            
            if(loadng == 'contactlist'){
                document.getElementById("preloading").innerHTML = '';
            }

            if(loadng == 'monthset'){
                ReferentiesSlider();
            }

            if(loadng == 'newsrecords'){
                panelname = "yearpanel";
                make_curve(panelname);
            }

            if(loadng == 'worker'){
                panelname = "workerspanel";
                make_curve(panelname);
            }

            if(loadng == 'changeimage'){
                panelname = "paneset";
                make_curve(panelname);
            }

            if(loadng == 'section'){
                panelname = "panelsetting";
                make_curve(panelname);
				PorfolioSlider();
            }
            
            if(loadng == 'recordset'){
                panelname = "pane2";
                make_curve(panelname);

                $('.ohh').removeClass('current');
                $('.cantstop-'+id).addClass('current');
           }
    }
}
function GetXmlHttpObject(){
	if (window.XMLHttpRequest){
	  return new XMLHttpRequest();
	}
	if (window.ActiveXObject){
	  return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}
/*
Global = new function(){

    this.Delegates = array();
    var Me = this;
    this.Load = function(){

        $(ducument).ready(function(){
            for(var i in Me.Delegates){
                Me.Delegates.call();
            }
        });
    }

    this.SubscrimeToDOMReady = function (callback){
        Me.Delegates.push(callback);
    }
}

Global.SubscrimeToDOMReady(function(){

   
});
*/


$(document).ready(function() {
    
   $("#flowpanes").scrollable({circular: true, mousewheel: false}).navigator({
        navi: "#flowtabs",
        naviItem: 'li',
        activeClass: 'current',
        history: false
     });
   
    // para sa footer//
        $(".dapikol").click(function (){
           $(".footer_close").slideUp("slow");
           $(".showmethis").css('display', 'block');
           $(".footer_opening").css('display', 'none');
           $(".footer_open").slideDown("slow");
        });

        $(".showmethis").click(function (){
            $(".footer_close").slideDown("slow");
            $(".showmethis").css('display', 'none');
            $(".footer_opening").css('display', 'block');
            $(".footer_open").slideUp("slow");
        });

        $('div.accordionButton').click(function() {
            $('div.accordionContent').slideUp('normal');
            $(this).next().slideDown('normal');
        });

        $("div.accordionContent").hide();


	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
               
                if($(this).find("a").attr('class') == 'sale'){
                   
                    panelname = "panelsetting";
                    make_curve(panelname);
                    PorfolioSlider();




                }

                if($(this).find("a").attr('class') == 'community'){
                    ReferentiesSlider();
                }
				

		//Calculate width of all ul's
		(function($) {
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {
					rowWidth += $(this).width();
				});
			};
		})(jQuery);

		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;
			//Calculate each row
			$(this).find(".row").each(function() {
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});

		} else { //If row does not exist...

			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});

		}
	}

	function megaHoverOut(){
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide();
	  });
	}


	var config = {
		 sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)
		 interval: 100, // number = milliseconds for onMouseOver polling interval
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
		 timeout: 300, // number = milliseconds delay before onMouseOut
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);


        panelname = 'makecureforlistone';
        make_curve(panelname);

        panelname = 'makecureforlisttwo';
        make_curve(panelname);

        panelname = 'scrolltab';
        make_curve(panelname);

        panelname = 'scrollfirst';
        make_curve(panelname);

        panelname = 'scrollsecond';
        make_curve(panelname);

        panelname = 'scrolllastfirst';
        make_curve(panelname);

        panelname = 'scrolllastsecond';
        make_curve(panelname);

});

function make_curve(idcurve){
     $('#'+idcurve).jScrollPane({showArrows:true});
         var scroller = {
          tl: { radius: 5 },
          tr: { radius: 4 },
          bl: { radius: 5 },
          br: { radius: 5 },
          antiAlias: true
        }
        curvyCorners(scroller, ".jScrollPaneDrag");
       
}


function ReferentiesSlider()
{
	var imgSize = $(".imgContent").size();
	$("#mNext").click(function(){
		if (clickNumber>=imgSize)
			return;
		clickNumber+=1;

		var left = $(".ReferentiesContent").css("margin-left");
		left=left.replace("px", "");
		left = (parseInt(left)) - parseInt($(".imgContent").width());
		$(".ReferentiesContent").animate({"marginLeft":left, "easing": "easein"},300 );
	});

	$("#mPrev").click(function(){
		if (clickNumber<=1)
			return;
		clickNumber -=1;

		var left = $(".ReferentiesContent").css("margin-left");
		left=left.replace("px", "");
		left = parseInt(left) + parseInt($(".imgContent").width());
		$(".ReferentiesContent").animate({"marginLeft":left, "easing": "easein"},300);
	});
}

function PorfolioSlider()
{
	var imgSize = $(".porfolioContent").size();
	$("#Nextport").click(function(){
		if (clickNumber>=imgSize)
			return;
		clickNumber+=1;

		var left = $(".ReferentiesContener").css("margin-left");
		left=left.replace("px", "");
		left = (parseInt(left)) - parseInt($(".porfolioContent").width());
		$(".ReferentiesContener").animate({"marginLeft":left, "easing": "easein"},300 );
	});

	$("#Previewport").click(function(){
		if (clickNumber<=1)
			return;
		clickNumber -=1;

		var left = $(".ReferentiesContener").css("margin-left");
		left=left.replace("px", "");
		left = parseInt(left) + parseInt($(".porfolioContent").width());
		$(".ReferentiesContener").animate({"marginLeft":left, "easing": "easein"},300);
	});
}
