﻿$(function() {
//Function Name: Onload
//Created by: KieuGiang
window.onload = function(){
	
	if ($("#content").height()<720) {
	$("#content").height(720);
	}
	else{
	$("#right").css("height",$("#content").height());
	$("#left").css("height",$("#content").height());
	}
	//$("#right").css("height",$("#content").height());
	//$("#right").css("background", "url(tl_files/wine/images/right_bar.jpg)");
		//$("#left").css("height",$("#content").height());
		//$("#left").css("background", "url(tl_files/wine/images/left_bar.jpg)");
		
		$("#footer1").css("top",$("#content").height() + 258);
		$("#footer1").css("display","block");
		$("#banner1").css("top",$("#content").height() + 258);
		$("#banner1").css("display","block");
		//$("#footer").css("top", $("#content").height()+258);
		//alert($("#main").height());
		//background: url(tl_files/wine/images/left.gif)
		
		
		setTitleName();
		
		////if (window.location=="http://tuankietsteel.com/wine/index.php")
		//{ 
		$('#slider').nivoSlider({controlNav:false});
		$('#gallery a').lightBox({ flag:true,textContent:'<div style="text-align:left;"><strong>Club Night Venue</strong><div><div><strong>Fairway Lodge</strong>, adjacent to (behind) the North Shore Events Centre and (adjacent to) the golf course. </div><div>Enter via Argus Place, off Sunnybrae Road, Glenfield. </div>'});
		$('#gallery1 a').lightBox({ flag:true,textContent:'<div style="text-align:left;"><strong>Club Night Venue</strong><div><div><strong>Fairway Lodge</strong>, adjacent to (behind) the North Shore Events Centre and (adjacent to) the golf course. </div><div>Enter via Argus Place, off Sunnybrae Road, Glenfield. </div>'});
			drawleftbar();
			loaddatafornewsletter();
			
		//}
};
function loaddatafornewsletter()
{
	
var months = new Array("Please Select","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

 //var combo = document.getElementById("combo"); 
	for(i=0; i<months.length;i++)
	{
		var elm = document.createElement("option");
		elm.text = months[i];
		elm.value = i;
		$("#combo")[0].options[$("#combo")[0].options.length] = elm; //Standard
	}
	$('#newsletter').append($("#combo"));
}


function drawleftbar(){
	$.ajax({
		 type:"POST",
		 url:"tl_files/wine/php/getmonthlyclubnights.php",
		 success:function(MonthlyWineClubContent){
			 drawleftbar_callback(MonthlyWineClubContent);
		 }});
}

function ShowMonthlyClubNight(id)
{
	$.ajax({
		 type:"POST",
		 url:"tl_files/wine/php/monthlyclubnight.php?id="+id.currentTarget.value,
		 success:function(content){
			 ShowMonthlyCLubContent_callback(content);
		 }
		});

}
function ShowMonthlyCLubContent_callback(content)
{	
	ShowNextEvent(content, "Club Night Information");
}
function drawleftbar_callback(MonthlyWineClubContent)
{
MonthlyWineClubContent = eval(MonthlyWineClubContent);
var htmltext;

		for (var i = 0; i < MonthlyWineClubContent.length; i++) {
				var ClubNightContent = MonthlyWineClubContent[i];
				var monthlyclub
				if(i == 0)
				{
					 monthlyclub = $("<div>").attr({value:ClubNightContent.id,id:"currentmonthclub"}).html(ClubNightContent.monthlyclub);
				}
				else{
					monthlyclub = $("<div>").attr({value:ClubNightContent.id,id:"monthlyclub"}).html(ClubNightContent.monthlyclub);
				}
				
                var details = $('<a>').attr({value:ClubNightContent.id,id:'ViewDetails'}).html(ClubNightContent.shortcontent);
				details.css("cursor","pointer");
				var id = ClubNightContent.id;
				details.click(function(id){ShowMonthlyClubNight(id)});
		        monthlyclub.append("<br />");		
                monthlyclub.append(details);
				var content = $('<div>').attr({value:ClubNightContent.id,id:'monthlyclubcontent'});
				$('#leftbar').append(monthlyclub);  
				$('#leftbar').append(content);
		}
}
var pagename;

function setTitleName()
{
	
	var urlparts = document.URL.split("/");
	pagename = urlparts[urlparts.length - 1].split(".")[0];
	
	if(pagename == "index" || pagename =="HomePage")
	{
		document.getElementById('imgHome').src ='tl_files/wine/images/HomeHover.gif'; 

	}
	else if(pagename =="TastingNotes")
	{
		document.getElementById('imgTasting').src ='tl_files/wine/images/TastingNotes.gif'; 
	}
	else if(pagename =="AucklandWineFoodEvents")
	{
		document.getElementById('imgWineFood').src ='tl_files/wine/images/Wine&FoodHover.gif'; 
	}
	else if(pagename =="PastEvents")
	{
		document.getElementById('imgPastEvents').src ='tl_files/wine/images/PastEventHover.gif'; 
	}
	else if(pagename =="WineFoodLink")
	{
		document.getElementById('imgWineFoodLink').src ='tl_files/wine/images/WineFoodLinkHover.gif';
	}
	else{
		document.getElementById('imgContact').src ='tl_files/wine/images/ContactHover.gif'; 
	}

};

$("#NextEvent").click(function() {
	$.ajax({
     type:"POST",
     url:"tl_files/wine/php/getnextevent.php",
     success:function(content){
		 ShowNextEvent(content,"Next Event");
     }
    });
});
$("#combo").change(function() {
	
	var monthvalue = ($("#combo")[0].options[$("#combo")[0].selectedIndex].text).toLowerCase();
	window.open("tl_files/wine/newsletters/"+ monthvalue + ".pdf");
});
$("#NextEvent1").click(function() {
	$.ajax({
     type:"POST",
     url:"tl_files/wine/php/getnextevent.php",
     success:function(content){
		 ShowNextEvent(content,"Next Event");
     }
    });
});

	$.fx.speeds._default = 1000;
	$( "#dialog" ).dialog({
			autoOpen: false,
			show: "blind",
			hide: "explode",
			height: 570,
			width:650
		});

	
function ShowNextEvent(content,titlename){
$("#dialog").html(content);
$("#dialog").dialog("option","title",titlename);
$('#dialog').dialog('open');
					return false;
}


$("#divclose").click(function() {
$("#dialog").hide();
});


$("#TastingNodes").mouseover(function() {
	
		document.getElementById('imgTasting').src ='tl_files/wine/images/TastingNotes.gif'; 
		//$("#imgTasting").attr('src','tl_files/wine/images/TastingNotes.gif');
		return true;
});

$("#TastingNodes").mouseout(function() {
	if(pagename != "TastingNotes")
	{
		//$("#imgTasting").attr('src','tl_files/wine/images/page-_slices_09.gif');
		document.getElementById('imgTasting').src = 'tl_files/wine/images/page-_slices_09.gif';
	}
});

$("#WineFood").mouseover(function() {
	
		document.getElementById('imgWineFood').src ='tl_files/wine/images/Wine&FoodHover.gif'; 
		//$("#imgTasting").attr('src','tl_files/wine/images/TastingNotes.gif');
		return true;
});

$("#WineFood").mouseout(function() {
	if(pagename != "AucklandWineFoodEvents")
	{
		//$("#imgTasting").attr('src','tl_files/wine/images/page-_slices_09.gif');
		document.getElementById('imgWineFood').src = 'tl_files/wine/images/Wine&Food.gif';
	}
});

$("#PastEvents").mouseover(function() {
		document.getElementById('imgPastEvents').src ='tl_files/wine/images/PastEventHover.gif'; 
		//$("#imgTasting").attr('src','tl_files/wine/images/TastingNotes.gif');
		return true;
});

$("#PastEvents").mouseout(function() {
	if(pagename != "PastEvents")
	{
		//$("#imgTasting").attr('src','tl_files/wine/images/page-_slices_09.gif');
		document.getElementById('imgPastEvents').src = 'tl_files/wine/images/PastEvent.gif';
	}
});

$("#WineFoodLink").mouseover(function() {
	
		document.getElementById('imgWineFoodLink').src ='tl_files/wine/images/WineFoodLinkHover.gif'; 
		//$("#imgTasting").attr('src','tl_files/wine/images/TastingNotes.gif');
		return true;
});

$("#WineFoodLink").mouseout(function() {
	if(pagename != "WineFoodLink")
	{
		//$("#imgTasting").attr('src','tl_files/wine/images/page-_slices_09.gif');
		document.getElementById('imgWineFoodLink').src = 'tl_files/wine/images/WineFoodLink.gif';
	}
});

$("#Contact").mouseover(function() {
	
		document.getElementById('imgContact').src ='tl_files/wine/images/ContactHover.gif'; 
	//$("#imgTasting").attr('src','tl_files/wine/images/TastingNotes.gif');
	return true;
	

});

$("#Contact").mouseout(function() {
	if(pagename != "Contact")
	{
	//$("#imgTasting").attr('src','tl_files/wine/images/page-_slices_09.gif');
document.getElementById('imgContact').src = 'tl_files/wine/images/Contact.gif';
	}
});

$("#Home").mouseover(function() {
		document.getElementById('imgHome').src ='tl_files/wine/images/HomeHover.gif'; 
	//$("#imgTasting").attr('src','tl_files/wine/images/TastingNotes.gif');
	return true;
	

});

$("#Home").mouseout(function() {
	//$("#imgTasting").attr('src','tl_files/wine/images/page-_slices_09.gif');
	if( pagename != "index")
	{
		document.getElementById('imgHome').src = 'tl_files/wine/images/Home.gif';
	}
});
$("#ViewVenue").mouseover(function() {
		document.getElementById('imgHome').src ='tl_files/wine/images/HomeHover.gif'; 
	//$("#imgTasting").attr('src','tl_files/wine/images/TastingNotes.gif');
	return true;
	

});

$("#ViewVenue").mouseout(function() {
	//$("#imgTasting").attr('src','tl_files/wine/images/page-_slices_09.gif');
	if( pagename != "index")
	{
		document.getElementById('imgHome').src = 'tl_files/wine/images/Home.gif';
	}
});

function showDialog(name, content) {	
		// picture name
		$("#dialog").html(content);
		var left = (screen.width/2)-($("#dialog").width()/2);
//var top = (screen.height/2)-($("#dialog").height/2);
		// personal detail
		//$('#scroll').html(content);=> bo scroll di ong can vay lam sao no biet html, lay html cua dialog bo vao dauanh bo thu xem
		//$('#scroll').css('top',37);
		$("#dialog").css('top',37);
		$("#dialog").css('left',left);
		$("#dialog").show();
		//$("#dialog").css('left',50).show();
	}
});
