var points = [];
var markers = [];
var marker_html1 = [];
var marker_html2 = [];
var counter = 0;
var map = null;
        
function init_maps(LATITUDE,LONGITUDE) {
    var mapObj = document.getElementById("map");
    if (mapObj != "undefined" && mapObj != null) {
        map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(LATITUDE,LONGITUDE), 15);

        contMap = new GSmallMapControl();
        contMapPoint = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(20,115));

        contType = new GMapTypeControl();
        contTypePoint = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(200,0));

        map.addControl(contMap,contMapPoint);
        map.addControl(contType,contTypePoint);

        //ベースアイコン-シャドウアイコン
        var baseIcon = new GIcon();
//    baseIcon.image = "images/lamian.bmp";
//    baseIcon.shadow = "images/hotel_icon_shadow.png";
//    baseIcon.iconAnchor = new GPoint(16,38);
//    baseIcon.infoWindowAnchor = new GPoint(16,4);
        baseIcon.image="http://maps.google.co.jp/mapfiles/ms/icons/orange-dot.png";
        baseIcon.shadow="http://maps.google.co.jp/mapfiles/ms/icons/orange-dot.shadow.png";
        baseIcon.iconSize=new GSize(32,32);
        baseIcon.shadowSize=new GSize(59,32);
        baseIcon.iconAnchor=new GPoint(16,32);
        baseIcon.infoWindowAnchor=new GPoint(16,0);

        //マーカーオブジェクト生成
        for(i=0;i<map_category_shop.length;i++){
            var point = new GLatLng(map_category_shop[i].LATITUDE,map_category_shop[i].LONGITUDE);
            var html1="<div id='balloon'>"+
        "<h3>"+map_category_shop[i].SHOP_NAME+"</h3>"+
        "<img src='../../images/shop/pop/" + map_category_shop[i].SHOP_ID + ".jpg' border='0' class='photo'>"+
        "<div class='data'>"+
        "<table border='0' cellspacing='1' cellpadding='5'>"+
        "<tbody>"+
        "<tr><th>営業時間</th><td>"+
        map_category_shop[i].BUSINESS_HOURS+
        "</td>"+
        "<th>休み</th><td>"+
        map_category_shop[i].SHOP_HOLIDAY+
        "</td></tr>"+
        "<th>イチオシ</th><td colspan='3'>"+
        map_category_shop[i].RECOMMEND+
        "</td></tr>"+
        "<tr><th>ラインアップ</th><td colspan='3'>"+
        map_category_shop[i].LINE_UP+
        "</td></tr>"+
        "<tr><th>駐車場</th><td colspan='3'>"+
        map_category_shop[i].PARKING+
        "</td></tr>"+
        "<tr><th>住所</th><td colspan='3'>"+
        map_category_shop[i].city_name+map_category_shop[i].district_name+map_category_shop[i].SHOP_ADDRESS+
        "</td></tr>"+
        "<tr><th>電話</th><td colspan='3'>"+
        map_category_shop[i].SHOP_TEL+
        "</td></tr>"+
        "<tr><th>メール</th><td colspan='3'>"+
        map_category_shop[i].SHOP_MAIL+
        "</td></tr>"+
        "<tr><th>ホームページ</th><td colspan='3'>"+
        map_category_shop[i].SHOP_URL+
        "</td></tr>"+
        "<tr><th>お店の紹介</th><td colspan='3'>"+
        map_category_shop[i].SHOP_PR+
        "</td></tr>"+
        "</tbody></table></div>"+
        "<div class='qr'><img src='../images/qr/getcoupon/"+
        map_category_shop_coupon[i].COUPON_ID+".jpg' border='0'><p>クーポン取得はこちら</p><div class='outline'></div>"+
        "</div>";
        var html2 = "<div id='balloon'>"+
        "<h3>"+map_category_shop[i].SHOP_NAME+"</h3>"+
        "<table valign='top' width='500'><tr><td>";
        
        if( map_category_shop[i].COUPON_HIT_TITLE != ""){
            html2 += "<table border='1' cellpadding='1' cellspacing='1' width='200' height='100'>"+
        "<tr><td valign='top' height='10' bgcolor='"+
        map_category_shop_coupon[i].COUPON_BGCOLOR+"'>"+
        "<center><img src='../images/shop_image/0000/0007/coupon_hit_header.jpg' width='200'></center>"+ 
        "<center><font color='"+ 
        map_category_shop_coupon[i].COUPON_FONTCOLOR+"' size='+1'>"+
        map_category_shop[i].COUPON_HIT_TITLE+
        "</font></center>"+
        "<center><font color='"+
        map_category_shop_coupon[i].COUPON_FONTCOLOR+"' size='+1'>【"+
        map_category_shop[i].SHOP_NAME+
        "】</font></center>"+
        "<center><img src='../images/shop_image/0000/0010/coupon_hit_footer.jpg' width='200'></center>"+ 
        "</td></tr>"+
        "</table>";
        }
        
        html2 += "<table border='1' cellpadding='1' cellspacing='1' width='200' height='100'>"+
        "<tr><td valign='top' height='10' bgcolor='"+
        map_category_shop_coupon[i].COUPON_BGCOLOR+"'>"+
        "<center><img src='../images/shop_image/0000/0001/coupon_header.jpg' width='200'></center>"+ 
        "<center><font color='"+ 
        map_category_shop_coupon[i].COUPON_FONTCOLOR+"' size='+1'>"+
        map_category_shop_coupon[i].COUPON_TITLE+
        "</font></center>"+
        "<center><font color='"+
        map_category_shop_coupon[i].COUPON_FONTCOLOR+"' size='+1'>【"+
        map_category_shop[i].SHOP_NAME+
        "】</font></center>"+
        "<center><img src='../images/shop_image/0000/0004/coupon_footer.jpg'  width='200'></center>"+ 
        "</td></tr>"+
        "</table>"+
        "</td><td align='center' valign='middle'>";
        if (get_coupon_flg == 1) {
            html2 += "↓をクリックするとクーポンを取得できます♪<br>大当たりクーポンがある場合は、<br>どちらかのクーポンが当たります!<form action='/pc_user/map_top'><input type='hidden' name='coupon_id' value='"+ map_category_shop_coupon[i].COUPON_ID+ "'/><input type='hidden' name='map_id' value='"+ current_map_id + "'/><input type='hidden' name='menu' value='get_coupon'/><input type='submit' value='Myクーポンに登録'/></form><br/>取得したクーポンは、携帯で持ち運べます!<br>お店でクーポン画面を見せて、<br>使ってくださいね★";
        }else{
//            html2 += "<div class='qr'><img src='../images/qr/getcoupon/"+
        map_category_shop_coupon[i].COUPON_ID+".jpg'><p>クーポン取得はこちら</p><div class='outline'></div>"+
        "</div><br><br>※<font color='green'>きずなアプリ</font>を起動してショットしてね!<br>※<font color='green'>きずなアプリ</font>は、QRコードをショットすると無料でダウンロードできます";
            html2 += "<div class='qr'><img src='../images/qr/getcoupon/"+
        map_category_shop_coupon[i].COUPON_ID+".jpg'><p>クーポン取得はこちら</p><div class='outline'></div>"+
        "</div><br><br>※QRｺｰﾄﾞをｼｮｯﾄして、お店詳細画面から特典ｸｰﾎﾟﾝを選択してｸｰﾎﾟﾝをｹﾞｯﾄ!<br>※お店にｸｰﾎﾟﾝ画面を見せてくださいね♪";
        }
        html2 += "</td></tr>"+
        "</table>"+
        "</div>";
            var marker = createMarker(point,html1,html2,baseIcon);
            map.addOverlay(marker);
        }
        if(counter==1){
          click_sidebar(0);
        }
    } else {
        alert("Sorry, the Google Maps API is not compatible with this browser.");
    }
}
function createMarker(point,html1, html2,baseIcon){
    var marker = new GMarker(point,{icon:baseIcon});
    var infoTabs = [
        new GInfoWindowTab("お店情報", html1),
        new GInfoWindowTab("クーポン", html2)];
//        var maxContentDiv = document.createElement('div');
//        maxContentDiv.style.textAlign = 'center';
//        maxContentDiv.style.width = '560px';
//        maxContentDiv.style.height = '330px';
//        maxContentDiv.innerHTML = 'Loading panorama';
    GEvent.addListener(marker, "click", function() {
//            marker.openInfoWindowHtml(description,{maxContent :maxContentDiv});
        marker.openInfoWindowTabsHtml(infoTabs);
    });
    points[counter] = point;
    markers[counter] = marker;
    marker_html1[counter] = html1;
    marker_html2[counter] = html2;
    counter++;
    return marker;
}
function isArray(a) {return isObject(a) && a.constructor == Array;}
function isObject(a) {return (a && typeof a == 'object') || isFunction(a);}
function isFunction(a) {return typeof a == 'function';}
function click_sidebar(idx) {
    var infoTabs = [
        new GInfoWindowTab("お店情報", marker_html1[idx]),
        new GInfoWindowTab("クーポン", marker_html2[idx])];
    markers[idx].openInfoWindowTabsHtml(infoTabs);
}
function showInfoWindow(idx,html) {
map.centerAtLatLng(points[idx]);
markers[idx].openInfoWindowHtml(html);
}

