﻿/* timers */
var timer1;
var timer2;

/*list of top level tier elements for timer tracking */
var tierLists;
var tier2Lists;
		
$(document).ready(function() 
{

	tierLists = $(".tier1_nav");
	for(var i in tierLists)
		tierLists[i].index = i;

	tier2Lists = $(".tier2_nav");
	for(var j in tier2Lists)
		tier2Lists[j].index = j;

	/* nav level fade handlers */
	$(".tier1_nav").hover
	(
		function()
		{
			//hide any straggler lists that may persits
			$(".tier1_nav").children("ul").css("display","none");
			//$(this).children("ul").fadeIn("fast");		
			timer1 = setTimeout("showTier("+this.index+")",100);
		},
		function()
		{
			$(this).children("ul").css("display","none");
			clearTimeout(timer1);
		}		
	);

	/* second level nav level fade handlers */
	$(".tier2_nav").hover
	(
		function()
		{
			//hide any straggler lists that may persits
			$(".tier2_nav").children("ul").css("display","none");
			//$(this).children("ul").fadeIn("fast");
			timer2 = setTimeout("showTier2("+this.index+")",200);
		},
		function()
		{
			$(this).children("ul").css("display","none");
			clearTimeout(timer2);
		}		
	);
	
	/* hide persistant menus when hover over a primary nav link that does not have sub levels */
	$("#home, #contact_us").mouseover
	(
		function ()
		{
			$(".tier1_nav").children("ul").css("display","none");
		}
	);
	
	/* Google Map*/
	load();
	
	/* rotate headlines*/
	try
	{
	    if(isDefault)
	        loadHeadings();
	
	} catch (e) {
	    
	}
});

function showTier(listIndex)
{
	//$(tierLists[listIndex]).children("ul").fadeIn("fast");
	$(tierLists[listIndex]).children("ul").css("display","block");
}

function showTier2(listIndex)
{
	$(tier2Lists[listIndex]).children("ul").fadeIn("fast");
}



    var address = "6160 Lusk Blvd San Diego, CA 92121";
    var displayAddress = "Syndicated Methods, Inc.<br/>" +
                        "6160 Lusk Blvd. Suite C-203<br/>" +
                        "San Diego, CA 92121<br/>" +
                        "USA";
    function load() 
    {
        try
        {
            var map = new GMap2(document.getElementById("map"));
        } catch (e) {    
            return;
        }
        
        map.addControl(new GSmallMapControl());

        var geocoder = new GClientGeocoder();
        geocoder.getLatLng(
            address,
            function(point) {
              if (!point) {
                alert(address + " not found");
              } else {
                map.setCenter(point, 13);
//alert(point.lat() + " : " + point.lat());
                map.panDirection(0,1);
                var marker = new GMarker(point);
                map.addOverlay(marker);
                marker.openInfoWindowHtml(displayAddress);
              }
            }
          );
    }

function loadHeadings()
{
    $.ajax({
      type: "GET",
      url: "headline_reviews.xml",
      dataType: "xml",
      async: false,
      success: function(xml,msg)
      {
        headline_reviews = $('review',xml);
        $('review',xml).each
        (function(i){
            //alert($(this).text());
        });
      }
    });
    
    headline_reviews.each
        (function(i){
            //alert($(this).text());
        });

    
    addHeadline(Math.floor(Math.random()*3));
}    

function removeHeadline()
{
    $("#headline > *").each
        (function(){
            $(this).fadeOut(2000);
        });
    $("#headline > p").fadeOut(2000);    
       
    setTimeout("addHeadline()",2000);
}

function addHeadline(seed)
{
    $("#headline").empty();
    $("#headline > p").remove();
    
    if (seed)
    {
        current_headline = seed;
    }
        
    var headline = $(headline_reviews[current_headline]).find("headline").text();
    var quote = $(headline_reviews[current_headline]).find("quote").text();
    
    if(++current_headline >= headline_reviews.length)
        current_headline = 0;
    
    $("#headline").html("<h1>" + headline + "</h1><p>" + quote + "</p>").find("*").each(function(){$(this).hide()});
    /*var p = document.createElement('p');
    p.appendChild(document.createTextNode(quote));
    //$(p).hide();
    p.style.display = 'none';
    document.getElementById('headline').appendChild(p);*/
    //$("#headline").append("<p>" + quote + "</p>").find("p").each(function(){$(this).hide()});
    
    $("#headline > *").each
        (function(){
            $(this).fadeIn(1000);
        });
    $("#headline > p").fadeIn(1000);        
        
   //return;
   setTimeout("removeHeadline()",5000);
}

//used for news and events page
function showDiv(objectID) 
{
            var theElementStyle = document.getElementById(objectID);
            if(theElementStyle.style.display == "block"){
                theElementStyle.style.display = "none";
            }
            else{
            theElementStyle.style.display = "block";}
}