﻿function preloadIcons() {
    if (document.images)
    {
        preload_image_object = new Image();
        image_url = new Array();
        image_url[0] = "images/delicious_32.png";
        image_url[1] = "images/facebook_32.png";
        image_url[2] = "images/google_32.png";
        image_url[3] = "images/linkedin_32.png";
        image_url[4] = "images/mixx_32.png";
        image_url[5] = "images/newsvine_32.png";
        image_url[6] = "images/reddit_32.png";
        image_url[7] = "images/myspace_32.png";
        image_url[8] = "images/stubleupon_32.png";
        image_url[9] = "images/technorati_32.png";
        image_url[10] = "images/twitter_32.png";
        image_url[11] = "images/www_32.png";
        image_url[12] = "images/yahoobuzz_32.png";
        image_url[13] = "images/email_32.png";
        var i = 0;
        for(i=0; i<13; i++) 
            preload_image_object.src = image_url[i];
        }    
}
function showsocialdetail(elem, detail) {
    jQuery('#socialcont').addClass('hide');
    jQuery('#socialoader').css('display', 'block');
    showTriangle(elem, detail);

    var t = jQuery('#menucont > div');

    t.each(
            function(index) {
                if (jQuery(this).attr('id') != elem) {
                    jQuery('#' + jQuery(this).attr('id') + ' .triangle').css('visibility', 'hidden');
                }
            }
        );
    jQuery('#socialoader').css('display', 'none');
    jQuery('#socialcont').removeClass('hide');
    var e = jQuery('#socialcont > div');
    e.each(
            function(index) {
                if (jQuery(this).attr('id') == detail) {
                    jQuery('#' + jQuery(this).attr('id')).removeClass('hide');
                } else {
                    jQuery('#' + jQuery(this).attr('id')).addClass('hide');
                }
            }
        );
    if (detail == 'twdetail') {
        jQuery('#twdetail').addClass('hide');
        jQuery('#socialcont').addClass('hide');
        jQuery('#socialoader').css('display', 'block');
        jQuery('#socialoader').css('display', 'none');
        jQuery('#twdetail').removeClass('hide');
        jQuery('#socialcont').removeClass('hide');
    } else if (detail == 'fbdetail') {
        jQuery('#smdetail').addClass('hide');
        FB.init("98edecca75d769bb0736de64c4532b29");
    } else if (detail == 'smdetail') {
        jQuery('#smdetail').removeClass('hide');
    } else if (detail == 'ypdetail') {
        jQuery('#smdetail').addClass('hide');
        jQuery('#socialcont').addClass('hide');
        jQuery('#socialoader').css('display', 'block');
        var url = encodeURI('http://api.yelp.com/business_review_search?callback=yelpreview&term=characters nyc&location=243 W 54th St,NYC,NY,10019&ywsid=oJJZ_q-kQ_RhFrEbDSnVww');
        //var url = encodeURI('http://api.yelp.com/v2/business/characters-nyc-new-york');
        var script = document.createElement('script');
        script.src = url;
        script.type = 'text/javascript';
        var head = document.getElementsByTagName('head').item(0);
        head.appendChild(script);
    }
}
function yelpreview(data) {
    if (data.message.text == "OK") {
        jQuery('#ypdetail').children().remove();
        jQuery('#socialoader').css('display', 'none');
        jQuery('#socialcont').removeClass('hide');
        for (var i = 0; i < data.businesses.length; i++) {
            var biz = data.businesses[i];
            if (biz.name == 'Characters NYC') {
                for (var j = 0; j < biz.reviews.length; j++) {
                    var review = biz.reviews[j];
                    mHTML = "<div class='twItem'><div class='twLeftItem'>" +
                                    "<img style='width:50px;height:50px;' src='" + review.user_photo_url + "' alt='" + review.user_name + "' class='juitterAvatar' />" +
                                    "<span style='width:50px;text-align:center;font-size:9px;'>" + review.user_name + "</span>" +
                                "</div>" +
					            "<div class='twRightItem'>" +
					                "<div class='twContent' style='font-size:10px;'><b>" + review.rating + " stars...</b> " + review.text_excerpt + "</div>" +
					                "<div class='twContext'>" +
					                    review.date +
					                    " | <a href='" + review.url + "' class='JRM' " + review.openLink + ">see more on Yelp</a>" +
					                "</div>" +
					             "</div></div>";
                    jQuery('#ypdetail').append(mHTML);
                }
            }
        }
    }
}
function getEvents() {
    $.get("events.xml",
            function(data) {
                var root = data;
                var result = $(root).find("item");
                var cal = ($('#cal-event > h3').text()).toLowerCase().split(' ');
                var calMonth = getMonthIndex(cal[0]);
                var calYear = cal[1];
                var days = $('#calblock a');
                var bDidMonth = false;
                var curDay = 0;
                days.each(function() {
                    var elem = $(this);
                    var day = elem.text();
                    var calDate = new Date(calMonth + '/' + day + '/' + calYear);
//                    if (day > curDay) {
//                        calMonth = (calMonth-- < 1) ? 12 : calMonth--;
//                        curDay = day;
//                    }

                    if (calMonth == 2 && day > 27) bDidMonth = true;
                    if (calMonth != 2 && day > 30) bDidMonth = true;
                    result.each(function() {
                        var eventDate = new Date($(this).attr('date'));
                        if ((eventDate.getDate() == day) && (eventDate.getDate() == calDate.getDate()) && eventDate.getMonth() == calDate.getMonth() && eventDate.getFullYear() == calDate.getFullYear()) {
                            if (bDidMonth == false) elem.addClass('event');
                        }
                    });
                });
            });
}
function loadmenu(menuname) {
    $("#fooddetail").empty();
    $("#fooddetail").addClass('hide');
    $("#menuloading").removeClass('hide');
    $.get("menu.xml",
            function(data) {
                //var result = $(data).find("section");
                var items;
                var note
                switch (menuname) {
                    case "appetizers":
                        items = $(data).find("section[name='Appetizers'] > menuitem");
                        items.each(function() {
                        note = '<div class="scrollcontentitemlarge"><div class="leftitem">menu</div><div class="rightitem"><span class="itemcost">price</span></div></div>';
                            note = note.replace("menu", "<span class='fooditem'>" + $(this).find('name').text() + "</span><span class='fooddesc'>" + $(this).find('description').text() + "</span>");
                            if ($(this).find('unit').length > 0) {
                                note = note.replace("price", $(this).find('price').text() + "<br/>" + $(this).find('unit').text());
                            } else {
                                note = note.replace("price", $(this).find('price').text());
                            }
                            $("#fooddetail").append(note);
                        });
                        break;
                    case "burgers":
                        items = $(data).find("section[name='Burgers and Sandwiches'] > menuitem");
                        items.each(function() {
                        note = '<div class="scrollcontentitemlarge"><div class="leftitem">menu</div><div class="rightitem"><span class="itemcost">price</span></div></div>';
                            note = note.replace("menu", "<span class='fooditem'>" + $(this).find('name').text() + "</span><span class='fooddesc'>" + $(this).find('description').text() + "</span>");
                            if ($(this).find('unit').length > 0) {
                                note = note.replace("price", $(this).find('price').text() + "<br/>" + $(this).find('unit').text());
                            } else {
                                note = note.replace("price", $(this).find('price').text());
                            }
                            $("#fooddetail").append(note);
                        });
                        break;
                    case "saladpasta":
                        items = $(data).find("section[name='Salads'] > menuitem");
                        items.each(function() {
                        note = '<div class="scrollcontentitemlarge"><div class="leftitem">menu</div><div class="rightitem"><span class="itemcost">price</span></div></div>';
                            note = note.replace("menu", "<span class='fooditem'>" + $(this).find('name').text() + "</span><span class='fooddesc'>" + $(this).find('description').text() + "</span>");
                            if ($(this).find('unit').length > 0) {
                                note = note.replace("price", $(this).find('price').text() + "<br/>" + $(this).find('unit').text());
                            } else {
                                note = note.replace("price", $(this).find('price').text());
                            }
                            $("#fooddetail").append(note);
                        });
                        items = $(data).find("section[name='Pasta'] > menuitem");
                        items.each(function() {
                        note = '<div class="scrollcontentitemlarge"><div class="leftitem">menu</div><div class="rightitem"><span class="itemcost">price</span></div></div>';
                            note = note.replace("menu", "<span class='fooditem'>" + $(this).find('name').text() + "</span><span class='fooddesc'>" + $(this).find('description').text() + "</span>");
                            if ($(this).find('unit').length > 0) {
                                note = note.replace("price", $(this).find('price').text() + "<br/>" + $(this).find('unit').text());
                            } else {
                                note = note.replace("price", $(this).find('price').text());
                            }
                            $("#fooddetail").append(note);
                        });
                        break;
                    case "pubfav":
                        items = $(data).find("section[name='Pub Favorites'] > menuitem");
                        items.each(function() {
                        note = '<div class="scrollcontentitemlarge"><div class="leftitem">menu</div><div class="rightitem"><span class="itemcost">price</span></div></div>';
                            note = note.replace("menu", "<span class='fooditem'>" + $(this).find('name').text() + "</span><span class='fooddesc'>" + $(this).find('description').text() + "</span>");
                            if ($(this).find('unit').length > 0) {
                                note = note.replace("price", $(this).find('price').text() + "<br/>" + $(this).find('unit').text());
                            } else {
                                note = note.replace("price", $(this).find('price').text());
                            } $("#fooddetail").append(note);
                        });

                        break;
                    case "sidesdesserts":
                        items = $(data).find("section[name='Sides'] > menuitem");
                        items.each(function() {
                        note = '<div class="scrollcontentitemsmall"><div class="leftitem">menu</div><div class="rightitem"><span class="itemcost">price</span></div></div>';
                            note = note.replace("menu", "<span class='fooditem'>" + $(this).find('name').text() + "</span><span class='fooddesc'>" + $(this).find('description').text() + "</span>");
                            if ($(this).find('unit').length > 0) {
                                note = note.replace("price", $(this).find('price').text() + "<br/>" + $(this).find('unit').text());
                            } else {
                                note = note.replace("price", $(this).find('price').text());
                            }
                            $("#fooddetail").append(note);
                        });
                        items = $(data).find("section[name='Desserts'] > menuitem");
                        items.each(function() {
                        note = '<div class="scrollcontentitemsmall"><div class="leftitem">menu</div><div class="rightitem"><span class="itemcost">price</span></div></div>';
                            note = note.replace("menu", "<span class='fooditem'>" + $(this).find('name').text() + "</span><span class='fooddesc'>" + $(this).find('description').text() + "</span>");
                            if ($(this).find('unit').length > 0) {
                                note = note.replace("price", $(this).find('price').text() + "<br/>" + $(this).find('unit').text());
                            } else {
                                note = note.replace("price", $(this).find('price').text());
                            }
                            $("#fooddetail").append(note);
                        });
                        break;
                    case "drinks":
                        items = $(data).find("section[name='Draft Beer'] > menuitem");
                        items.each(function() {
                        note = '<div class="scrollcontentitemsmall"><div class="leftitem">menu</div><div class="rightitem"><span class="itemcost">price</span></div></div>';
                            note = note.replace("menu", "<span class='fooditem'>" + $(this).find('name').text() + "</span><span class='fooddesc'>" + $(this).find('description').text() + "</span>");
                            if ($(this).find('unit').length > 0) {
                                note = note.replace("price", $(this).find('price').text() + "<br/>" + $(this).find('unit').text());
                            } else {
                                note = note.replace("price", $(this).find('price').text());
                            }
                            $("#fooddetail").append(note);
                        });
                        items = $(data).find("section[name='Bottled Beer'] > menuitem");
                        items.each(function() {
                        note = '<div class="scrollcontentitemsmall"><div class="leftitem">menu</div><div class="rightitem"><span class="itemcost">price</span></div></div>';
                            note = note.replace("menu", "<span class='fooditem'>" + $(this).find('name').text() + "</span><span class='fooddesc'>" + $(this).find('description').text() + "</span>");
                            if ($(this).find('unit').length > 0) {
                                note = note.replace("price", $(this).find('price').text() + "<br/>" + $(this).find('unit').text());
                            } else {
                                note = note.replace("price", $(this).find('price').text());
                            }
                            $("#fooddetail").append(note);
                        });
                        break;
                    default:
                        break;

                }
            });
            $("#menuloading").addClass('hide');
            $("#fooddetail").removeClass('hide');
}
function dateMatch(calDate, result, elem) {
    result.each(function() {
        var eventDate = new Date($(this).attr('date'));
        if (eventDate == calDate) {
            elem.parent().css('background-color', '#BF2A14');
        }
    });
}
function renderevents() {
    jQuery('#calcont').fadeIn(2000);
    jQuery('#eventcont').fadeIn(2000);
}
function getMonthIndex(s) {
    var m = new Array('january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december');
    for (var i = 0; i < m.length; i++) {
        if (s == m[i]) return i + 1;
    }
}  
function trimContent(cont, len) {
    if (cont.toString().length > len) {
        return cont.subString(len - 3) + '...';
    } else {
        return cont;
    }
}
function showEvent(date) {
    jQuery('#eventcont').css('display', 'none');
    jQuery('#noeventcont').css('display', 'none');
    jQuery('#eventloading').css('display', 'block');
    var m_names = new Array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
    jQuery('#eventpicimage').attr('src', '');
    jQuery('#eventlinks').html('');
    jQuery('#eventmonth').html(m_names[date.getMonth()].toUpperCase());
    jQuery('#eventday').html(date.getDate());

    jQuery.get("events.xml",
            function(data) {
                var root = data;
                var month = ((date.getMonth() + 1).toString().length == 1) ? '0' + (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString();
                var day = (date.getDate().toString().length == 1) ? '0' + date.getDate().toString() : date.getDate().toString();
                var result = jQuery(root).find("item[date='" + month + "/" + day + "/" + date.getFullYear().toString() + "']");
                if (result.length > 0) {
                    var name = jQuery(root).find("item[date='" + month + "/" + day + "/" + date.getFullYear().toString() + "'] title");
                    var desc = jQuery(root).find("item[date='" + month + "/" + day + "/" + date.getFullYear().toString() + "'] description");
                    var pic = jQuery(root).find("item[date='" + month + "/" + day + "/" + date.getFullYear().toString() + "'] image");
                    var links = jQuery(root).find("item[date='" + month + "/" + day + "/" + date.getFullYear().toString() + "'] link");
                    var start = jQuery(root).find("item[date='" + month + "/" + day + "/" + date.getFullYear().toString() + "'] start");
                    jQuery('#eventname').html(name[0].textContent);
                    if (desc[0].textContent.toString().length > 200) {
                        jQuery('#eventdescontent').addClass('smalloverflow');
                    } else {
                        jQuery('#eventdescontent').removeClass('smalloverflow');
                    }
                    jQuery('#eventdescontent').html(desc[0].textContent);
                    jQuery('#eventpicimage').attr('src', pic[0].textContent);
                    jQuery('#eventpicimage').attr('alt', name[0].textContent);
                    jQuery('#eventstarttime').html('Start: ' + start[0].textContent);
                    jQuery('#eventloading').css('display', 'none');
                    for (var n = 0; n < links.length; n++) {
                        if (links[n].textContent.toString().toUpperCase().indexOf("FACEBOOK") > -1) {
                            jQuery('#eventlinks').html(jQuery('#eventlinks').html() + "<a title='" + name[0].textContent + " on Facebook' href='" + links[n].textContent + "'><img alt='" + name[0].textContent + " on Facebook' src='images/facebook_32.png' /></a>");
                        } else if (links[n].textContent.toString().toUpperCase().indexOf("TWITTER") > -1) {
                            jQuery('#eventlinks').html(jQuery('#eventlinks').html() + "<a title='" + name[0].textContent + " on the Twitter' href='" + links[n].textContent + "'><img alt='" + name[0].textContent + " on Twitter' src='images/twitter_32.png' /></a>");
                        } else {
                            jQuery('#eventlinks').html(jQuery('#eventlinks').html() + "<a title='" + name[0].textContent + " on the web' href='" + links[n].textContent + "'><img alt='" + name[0].textContent + " on the web' src='images/www_32.png' /></a>");
                        }
                    }
                    jQuery('#noeventcont').css('display', 'none');
                    jQuery('#eventcont').fadeIn(2000);
                } else {
                    jQuery('#noeventmonth').html(m_names[date.getMonth()].toUpperCase());
                    jQuery('#noeventday').html(date.getDate());
                    jQuery('#noeventname').html('characters music');

                    var count = jQuery(data).find("item");
                    if (count.length > 1) {
                        count.each(function() {
                            var name = jQuery(this).find('title').text();
                            var pic = jQuery(this).find('image').text();
                            var links = jQuery(this).find("item link");
                            jQuery('#noeventscroller').append(
                            '<div style="height:80px;width:100%;display:block;border-bottom:1px dotted #cc9900;">' +
                            '<div id="recentperftitle" class="leftsmallbox">' + name + '</div>' +
                            '<div id="recentperfimgcont" class="hide" style="display:inline-block;height:80px;width:80px;background:#000;">' +
                            '<img id="recentperfimg" src="' + pic + '" alt="' + name +
                            '" style="height:80px;width:80px;" /></div></div>'
                            );
                            for (var n = 0; n < links.length; n++) {
                                if (links[n].textContent.toString().toUpperCase().indexOf("FACEBOOK") > -1) {
                                    jQuery('#eventlinks').html(jQuery('#eventlinks').html() + "<a title='" + name[0].textContent + " on Facebook' href='" + links[n].textContent + "'><img alt='" + name[0].textContent + " on Facebook' src='images/facebook_32.png' /></a>");
                                } else if (links[n].textContent.toString().toUpperCase().indexOf("TWITTER") > -1) {
                                    jQuery('#eventlinks').html(jQuery('#eventlinks').html() + "<a title='" + name[0].textContent + " on the Twitter' href='" + links[n].textContent + "'><img alt='" + name[0].textContent + " on Twitter' src='images/twitter_32.png' /></a>");
                                } else if (links[n].textContent.toString().toUpperCase().indexOf("MYSPACE") > -1) {
                                    jQuery('#eventlinks').html(jQuery('#eventlinks').html() + "<a title='" + name[0].textContent + " on the MySpace' href='" + links[n].textContent + "'><img alt='" + name[0].textContent + " on Twitter' src='images/mypsace_32.png' /></a>");
                                } else {
                                    jQuery('#eventlinks').html(jQuery('#eventlinks').html() + "<a title='" + name[0].textContent + " on the web' href='" + links[n].textContent + "'><img alt='" + name[0].textContent + " on the web' src='images/www_32.png' /></a>");
                                }
                            }
                        });
                        jQuery('#noloading').css('display', 'none');
                        jQuery('#noeventperformers').css('display', 'block');
                    }
                    jQuery('#eventloading').css('display', 'none');
                }
            });
}
function pastEvents() {
    jQuery('#noeventperformers').addClass('hide');
    jQuery('#noeventloading').removeClass('hide');
    jQuery('#noeventscroller').empty();
    jQuery.get("events.xml",
            function(data) {
                var root = data;
                var count = jQuery(data).find("item");
                if (count.length > 0) {
                    count.each(function() {
                        var name = jQuery(this).find('title').text();
                        var desc = jQuery(this).find('description').text();
                        var pic = jQuery(this).find('image').text();
                        var links = jQuery(this).find("item link");
                        jQuery('#noeventscroller').append(
                        '<div style="height:100px;width:100%;display:block;border-bottom:1px dotted #cc9900;">' +
                        '<div id="recentperftitle" class="leftsmallbox" style="width:140px;"><span class="eventititle">' + name + '</span><span class="eventnewdesc">' + desc + '</span></div>' +
                        '<div id="recentperfimgcont" style="display:inline-block;height:80px;width:80px;background:#000;">' +
                        '<img id="recentperfimg" src="' + pic + '" alt="' + name +
                        '" style="height:100px;width:100px;" /></div></div>'
                        );
                    });
                    jQuery('#noeventloading').addClass('hide');
                    jQuery('#noeventperformers').removeClass('hide');
                }
            });
}
function clean(s) {
    s = s.replace(/'/g, "\'");
    return s;
} 

function showAddressLabel(labelcont,address,zoom,iconpath) {
    jQuery('#' + labelcont).html(address);
    showAddressWithIcon(address, zoom, iconpath);
}
function loadModal() {
     //Get the screen height and width  
     var maskHeight = jQuery(document).height();  
     var maskWidth = jQuery(window).width();  
   
     //Set height and width to mask to fill up the whole screen  
     jQuery('#mask').css({'width':maskWidth,'height':maskHeight});  
       
     //transition effect       
     jQuery('#mask').fadeIn(1000);      
     jQuery('#mask').fadeTo("slow",0.8);    
   
     //Get the window height and width  
     var winH = jQuery(window).height();  
     var winW = jQuery(window).width();

     //Set the popup window to center
     //jQuery('#dialog').css('height', winH / 1.5);
     //jQuery('#dialog').css('height', '450');
     //jQuery('#dialog').css('width', winW / 3);
     //jQuery('#dialog').css('width', '320');
     //jQuery('#dialog').css('top', '50');
     //jQuery('#dialog').css('top', winH / 2 - jQuery('#dialog').height() / 2);
     jQuery('#dialog').css('left', winW / 2 - jQuery('#dialog').width() / 2);
     //jQuery('#bigmap').css('top', winH / 2 - jQuery('#dialog').height() / 2);
     //jQuery('#bigmap').css('left', winW / 2 - jQuery('#dialog').width() / 2);

//     setTimeout(function() {
//         map = new GMap2(document.getElementById("mainsplash"));
//         map.addControl(new GLargeMapControl3D());
//         map.addControl(new GScaleControl());
//         showAddressWithIcon("245 W 54th St, NYC,10019", 14, 'images/c.png');
//     }
//        , 1000);
     
     //transition effect
     jQuery('#dialog').fadeIn(2000);
     //jQuery('#bigmap').fadeIn(2000);
     //document.forms[2].txtBigFind.focus();
     //if close button is clicked  
//     jQuery('.window .close').click(function (e) {  
//         //Cancel the link behavior  
//         e.preventDefault();  
//         jQuery('#mask, .window').hide();  
//     });       
       
     //if mask is clicked  
     jQuery('#mask').click(function () {  
         jQuery(this).hide();  
         jQuery('.window').hide();  
     });
 }
 function closePoster() {
     jQuery('#dialog').hide();
     jQuery('#mask').hide();

 }
 function loadMap(address, cont) {
     map = new GMap2(document.getElementById(cont));
     var mapControl = new GSmallMapControl();
     map.addControl(mapControl);
     showAddressWithIcon(address, 14,'images/c.png');
 }
 function togglebigdirections() {
     if (jQuery('#bigfinder').css('display') == 'block') {
         jQuery('#bigfinder').hide();
         jQuery('#bigfind').css('height', '105px');
         jQuery('#bigaddress').html('Get directions');
         jQuery('#togglebigdirections').html('get address');
         document.forms[2].txtBigFind.focus();
         if (document.forms[2].txtBigFind.value != "") {
             document.forms[3].txtBigStart.value = document.forms[0].txtFind.value;
             document.forms[3].txtBigEnd.value = "245 W 54th St, NYC,10019";
         } else {
             document.forms[3].txtBigEnd.value = "245 W 54th St, NYC,10019";
         }
         jQuery('#bigdirections').fadeIn(2000);
     } else {
         jQuery('#bigdirections').hide();
         jQuery('#bigfind').css('height', '60px');
         jQuery('#bigaddress').html('Find address');
         jQuery('#togglebigdirections').html('get directions');
         document.forms[2].txtBigFind.focus();
         jQuery('#bigfinder').fadeIn(2000);
     }
 }
 function toggledirections() {
     if (jQuery('#finder').css('display') == 'block') {
         jQuery('#finder').hide();
         jQuery('#find').css('height', '105px');
         jQuery('#toggledirections').html('Enter directions');
         jQuery('#formtoggle').html('get address');
         document.forms[1].txtStart.focus();
         if (document.forms[0].txtFind.value != "") {
             document.forms[1].txtStart.value = document.forms[0].txtFind.value;
             document.forms[1].txtEnd.value = "245 W 54th St, NYC,10019";
         } else {
             document.forms[1].txtEnd.value = "245 W 54th St, NYC,10019";
         }
         jQuery('#directions').fadeIn(2000);
     } else {
         jQuery('#directions').hide();
         jQuery('#find').css('height', '60px');
         jQuery('#toggledirections').html('Enter address');
         jQuery('#formtoggle').html('get directions');
         document.forms[0].txtFind.focus();
         jQuery('#finder').fadeIn(2000);
     }
 }
 function togglewaypoints() {
     if (jQuery('#map').css('display') == 'block') {
         jQuery('#map').hide();
         jQuery('#route').fadeIn(2000);
         jQuery('#togglewaypoints').html('show map');
     }
     else {
         jQuery('#route').hide();
         jQuery('#map').fadeIn(2000);
         jQuery('#togglewaypoints').html('show waypoints');
     }
}
function find() {
    if (document.forms[0].txtFind.value.toString().length > 0) {
        var address = document.forms[0].txtFind.value.toString();
        showAddress(address, 12);
    }
}
function direct() {
    if (document.forms[1].txtStart.value.toString().length > 0 && document.forms[1].txtEnd.value.toString().length > 0) {
        directionsPanel = document.getElementById("route");
        var directions = new GDirections(map, directionsPanel);
        directions.clear();
        directions.load("from: " + document.forms[1].txtStart.value + " to: " + document.forms[1].txtEnd.value);
    }
}
 function searchFor(key) {
     var scope = key + ' in 10019';
     showAddress(scope, 12);
 }
 function showAddress(address, zoom) {
     var geocoder = new GClientGeocoder();
     geocoder.getLatLng(
        address,
        function(point) {
            if (!point) {
            } else {
                map.setCenter(point, zoom);
                var marker = new GMarker(point);
                map.addOverlay(marker);
            }
        }
      );
 }
 function showAddressWithIcon(address, zoom,iconpath) {
     var geocoder = new GClientGeocoder();
     geocoder.getLatLng(
        address,
        function(point) {
            if (!point) {
            } else {
                map.setCenter(point, zoom);
                var myIcon = new GIcon(G_DEFAULT_ICON);
                myIcon.image = iconpath;
                myIcon.iconSize = new GSize(20, 20);
                var markerOptions = { icon: myIcon };
                var marker = new GMarker(map.getCenter(), markerOptions);
                GEvent.addListener(marker, "click", function() {
                    marker.openInfoWindowHtml(address);
                });
                map.addOverlay(marker);
            }
        }
      );
 }
function showdetail(elem,detail) {
    var t = jQuery('#menucont > div');

    t.each(
        function(index) {
            if (jQuery(this).attr('id') != elem) {
                jQuery('#' + jQuery(this).attr('id') + ' .triangle').css('visibility', 'hidden');
            }
        }
    );

    var e = jQuery('.scrollcontent > div');
    e.each(
        function(index) {
            if (jQuery(this).attr('id') == detail) {
                jQuery('#' + jQuery(this).attr('id')).removeClass('hide');
            } else {
                jQuery('#' + jQuery(this).attr('id')).addClass('hide');
            }
        }
    );
}
function hideTriangle(elem, detail) {
    var d = jQuery('#' + detail).css('display');
    if (d != 'block') {
        jQuery('#' + elem + ' .triangle').css('visibility', 'hidden');
    }
}
function showTriangle(elem, detail) {
    jQuery('#' + elem + ' .triangle').css('visibility', 'visible');
}
function hideItem(elem, detail) {
    jQuery('#' + elem + ' .triangle').css('visibility', 'hidden');
}
function showItem(elem, detail) {
    jQuery('#' + elem + ' .triangle').css('visibility', 'visible');
}
function back() {
}
function stop() {
}
function play() {
    var e = jQuery('#galleryitems img');
    for (var n = 0; n < e.length; n++) {
        setTimeout
        (
            function(n,e) {
                e[n].src = 'images/closedcircle.png';
                jQuery('#currentpicture').remove();
                jQuery('#pictureframe').removeAttr('style');
                jQuery('#pictureframe').append("<img id='currentpicture' src='gallery/gallery" + (n + 1) + ".jpg' />");
                jQuery('#pictureframe').fadeIn(2000);
            },
            2000
        ); 
    }
}
function forward() {
}
function showpicture(n,items) {
    var sitem = 'photo' + n;
    for (var i = 0; i < items; i++) {
        var e = '#photo' + (i+1);
        var o = jQuery(e);
        if (o[0].id == sitem) {
            o[0].src = 'images/closedcircle.png';
            jQuery('#currentpicture').remove();
            jQuery('#pictureframe').removeAttr('style');
            jQuery('#pictureframe').append("<img id='currentpicture' src='gallery/gallery" + (i+1) + ".jpg' />");
            jQuery('#pictureframe').fadeIn(2000);
        } else {
            o[0].src = 'images/opencircle.png';
        }
    }
}
function render() {
    //jQuery('#welcome').fadeIn(1000);
    //jQuery('#picturecont').fadeIn(1000);
//    jQuery('#currentpicture').fadeIn(1000);
//    jQuery('#pictureframe').append("<img id='currentpicture' src='gallery/gallery1.jpg' alt=''/>");
//    jQuery('#pictureframe').fadeIn(1000);
////    if (getCookie("runOnce") != "1") {
//        jQuery('#bgImage').fadeIn(3000);
//        jQuery('#page').fadeIn(4000);
//        jQuery('#footer').fadeIn(4000);
//        jQuery('#menu').fadeIn(4000);
//        jQuery('#picturecont').fadeIn(4000);
//        jQuery('#leftpage').fadeIn(4000);
//        jQuery('#currentpicture').fadeIn(2000);
//        jQuery('#pictureframe').append("<img id='currentpicture' src='gallery/gallery1.jpg' alt='photo1'/>");
//        jQuery('#pictureframe').fadeIn(2000);
//        setCookie("runOnce", "1", 1);
//    } else {
//        jQuery('#menu').removeClass('hide');
//        jQuery('#menu').css('display','block');
//        jQuery('#bgImage').removeClass('hide');
//        jQuery('#page').removeClass('hide');
//        jQuery('#footer').removeClass('hide');
//        jQuery('#leftpage').removeClass('hide');
//        jQuery('#picturecont').removeClass('hide');
//        jQuery('#pictureframe').append("<img id='currentpicture' src='gallery/gallery1.jpg' alt='photo1'/>");
//        jQuery('#pictureframe').fadeIn(2000);
//    }
}
function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function highlight(elem,page) {
    var oElem = document.getElementById(elem);
    var oE = jQuery('#' + elem);
    oElem.className = 'menuitem active';
    if (elem != page) {
        oElem = document.getElementById(page);
        oElem.className = 'menuitem';
    }
}
function lowlight(elem,page) {
    var oElem = document.getElementById(elem);
    oElem.className = 'menuitem';
}
function refocus(elem) {
    var oElem = document.getElementById(elem);
    oElem.className = 'menuitem active';
}
