//Insert Flash Function
function insert_flash(file,div,width,height,transparent)
{
	var flashvars = {};
	if(transparent==1)
	{
		var params = {
		  wmode: "transparent",quality: "high"
		};
	}
	else
	{
	var params = {
	  quality: "high"
	  };
	}
		
	var attributes = {};
	swfobject.embedSWF(""+file+"", ""+div+"", ""+width+"", ""+height+"", "9.0.0","flash/expressInstall.swf", flashvars, params, attributes);
}
/*Tooltips*/
function initTooltips(){ $('a.hasTooltip[title!=""], span.hasTooltip[title!=""], div.hasTooltip[title!=""], img.hasTooltip[title!=""]').tipsy({gravity: $.fn.tipsy.autoNS}); $('a.hasTooltip.horizontalTipsy').tipsy({gravity: $.fn.tipsy.autoWE}); $('.hasTooltip.topTipsy').tipsy({gravity: 's'}); $('.hasTooltip.bottomTipsy').tipsy({gravity: 'n'});  /*, input[title]*//* $('a.horizTip').tipsy({gravity: "e"});*/ }
//External Links
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}
}

function share_click(type, url, title)
{
	var share_link;
	switch(type)
	{
		case "stumble":
			share_link = "http://www.stumbleupon.com/submit?url="+encodeURIComponent((url==""?location.href:url))+"&title="+encodeURIComponent((title==""?document.title:title))+"";
		break;
		case "twitter":
			share_link = "http://twitter.com/home?status="+encodeURIComponent((url==""?location.href:url))+"+"+encodeURIComponent((title==""?document.title:title))+"";
		break;
		case "friend":
			share_link = "http://www.friendfeed.com/share?url="+encodeURIComponent((url==""?location.href:url))+"&title="+encodeURIComponent((title==""?document.title:title))+"";
		break;
		case "delicious":
			share_link = "http://del.icio.us/post?url="+encodeURIComponent((url==""?location.href:url))+"&title="+encodeURIComponent((title==""?document.title:title))+"&notes=";
		break;
		case "facebook":
			share_link = "http://www.facebook.com/share.php?u="+encodeURIComponent((url==""?location.href:url))+"&title="+encodeURIComponent((title==""?document.title:title))+"";
		break;
		case "digg":
			share_link = "http://www.digg.com/submit?phase=2&url="+encodeURIComponent((url==""?location.href:url))+"&title="+encodeURIComponent((title==""?document.title:title))+"";
		break;
		case "linkedin":
			share_link = "http://www.linkedin.com/shareArticle?mini=true&url="+encodeURIComponent((url==""?location.href:url))+"&title="+encodeURIComponent((title==""?document.title:title))+"&summary=&source=";
		break;
		case "gbuzz":
			share_link = "http://www.google.com/buzz/post?url="+encodeURIComponent((url==""?location.href:url))+"&title="+encodeURIComponent((title==""?document.title:title))+"";
		break;
		case "technorati":
			share_link = "http://technorati.com/signup/?f=favorites&amp;Url="+encodeURIComponent((url==""?location.href:url))+"";
		break;
		case "myspace":
			share_link = "http://www.myspace.com/index.cfm?fuseaction=postto&t=" + encodeURIComponent((title==""?document.title:title))+"&c=&u=" + encodeURIComponent((url==""?location.href:url))+"";
		break;
		case "blogger":
			share_link = "http://www.blogger.com/blog_this.pyra?t=" + encodeURIComponent((title==""?document.title:title))+"&u=" + encodeURIComponent((url==""?location.href:url))+"";
		break;
	}
	window.open(share_link, 'sharer', 'toolbar=0,status=0,width=640,height=436');
}
var is_searching_archives = false;
var api;
function getNewsArchive(obj)
{
	$("#submenuContainer li a").removeClass("active");		
	$(obj).addClass("active");
	var val = $(obj).attr("id");
	
	if(!is_searching_archives) {
		is_searching_archives = true;
		jQuery('#rightSide div.monthNews').fadeOut().html("").parent().addClass("loader");
		jQuery.ajax({
			type: 'POST', 
			url: '/ajax/action/news-archive', 
			data: 'interval=' + val, 
			cache: false, 
			success: function(data){ 
				jQuery('#rightSide div.monthNews').html(data).fadeIn(500, function() { 
					$(this).parent().removeClass("loader");		
					
					initTooltips();	
					is_searching_archives = false;
				
				});
			}
		});
	} 
}
function getNewsletterArchive(obj)
{
	$("#submenuContainer li a").removeClass("active");
	$(obj).addClass("active");
	var val = $(obj).attr("id");
	
	if(!is_searching_archives) {
		is_searching_archives = true;
		jQuery('#rightSide div.monthNews').fadeOut().html("").parent().addClass("loader");
		jQuery.ajax({
			type: 'POST', 
			url: '/ajax/action/newsletter-archive', 
			data: 'interval=' + val, 
			cache: false, 
			success: function(data){ 
				jQuery('#rightSide div.monthNews').html(data).fadeIn().parent().removeClass("loader");
				initTooltips();

				is_searching_archives = false;
				
				externalLinks();
			}
		});
	} 
}
function initializeTooltip()
{
	// INITIALIZE TOOLTIP
	$(".imageHome a, .imageTeam img").tooltip({
		effect: 'slide',
		offset: [10, 2],
		slideOffset: 5,
		//onShow:function() { this.getConf().offset = [this.getTrigger().scrollTop().top, this.getTrigger().scrollTop().left]; }
	}).dynamic({ bottom: { direction: 'down', bounce: true } });
	
	// INITIALIZE TOOLTIP NEWS
	$(".newMonth a").tooltip({
		effect: 'slide',
		offset: [100, 250]
	});//.dynamic({ bottom: { direction: 'right', bounce: true } });

}
function reinitialiseScroll()
{
	$('.scrollPane').css("overflow","hidden");
	var scrollPane = $('.scrollPane');
	scrollPane.jScrollPane({verticalDragMinHeight:42, verticalDragMaxHeight:18, autoReinitialise:true, showArrows:true, verticalArrowPositions: 'os',animateTo:true, clickOnTrack:true, arrowButtonSpeed:20, mouseWheelSpeed:20 });	

	var api = scrollPane.data('jsp');

}
var isLoading = false;
function showLoading() 
{
	isLoading = true;
	var loadingContainer = $("<div>");
	loadingContainer.addClass("loader").attr("id","ajaxLoading").attr("style"," position:absolute; width:100%; height:100%; float:left; z-index:9999999; background-color:#f6f6f0; opacity: 0.8;	-moz-opacity: 0.8;	filter:alpha(opacity=80); ");
	//$(".jspContainer").append(loadingContainer);
	//$("div.monthNews, div.imageHome, div.newsHome",".jspContainer").css("visibility","visible");
}

function hideLoading()
{
	$("#ajaxLoading").fadeOut(1000, function() { $(this).remove(); });
	isLoading = false;
}
function showFilterButton()
{
	$(".closeFilterButton").fadeIn();
}
function hideFilterButton()
{
	$(".closeFilterButton").fadeOut();
}
function resizeScrollHeight()
{
	if($(".scrollPane").attr("id")=="")
	{
		$("#sizeScroll").css("height",'423px');
		var hScroll = $(".jspPane", ".jspContainer").height();
		var modScroll = Math.ceil(hScroll / 141);
		if(modScroll%3 != 0) modScroll++;
		if(modScroll%3 != 0) modScroll++;
		//while(modScroll%3 != 0) modScroll++;
		$("#sizeScroll").css("height",(( modScroll * 141 ))+'px');
		reinitialiseScroll();
	}
	else
	{
		reinitialiseScroll();	
	}	
}
function resizeImgObjects()
{
	if($(".imageGallery img"))
	{
		var wImg = $(".imageGallery img").attr("width");
		var hImg = $(".imageGallery img").attr("height");
		var wCont = $(".imageGallery img").parent().parent("#halfRightContainerCenter").width();
		var owImg = wImg, ohImg = hImg;
		//if(wImg > hImg)
		//{
			owImg = wCont;
			ohImg = (wCont * hImg) / wImg;
/*			if($width > $height) 
			{
			$w = $w;
			$h = ($w * $height) / $width;
			} 
			else 
			{
			$h = $h;
			$w = ($h * $width) / $height;
			}
	
	
*/		//}	

		$(".imageGallery img").attr("width",owImg);
		$(".imageGallery img").attr("height",ohImg);
		
	}	
}
$(window).load(function(){
		
	initTooltips();
	
	var stack_bottomright = {"dir1": "up", "dir2": "left", "firstpos1": 15, "firstpos2": 15};			
	$.pnotify.defaults.pnotify_insert_brs = false;
	$.pnotify.defaults.pnotify_width = "350px";
	$.pnotify.defaults.pnotify_title = '';
	$.pnotify.defaults.pnotify_hide = true;
	$.pnotify.defaults.pnotify_mouse_reset = true;
	$.pnotify.defaults.pnotify_before_close = function(pnotify){};
	$.pnotify.defaults.pnotify_opacity = 0.9;
	$.pnotify.defaults.pnotify_shadow = false;
	$.pnotify.defaults.pnotify_min_height = "30px";
	$.pnotify.defaults.pnotify_animation = {effect_in: 'fade', effect_out: 'fade'};//function(status, callback, pnotify){ }
	$.pnotify.defaults.pnotify_animate_speed = 1000;
	$.pnotify.defaults.pnotify_delay = 10000;
	$.pnotify.defaults.pnotify_history = false;
	$.pnotify.defaults.pnotify_stack = stack_bottomright;
			
	/*Load External Links*/
	externalLinks();
	var slideEffect = "easeInOutExpo";
	/*SIGNATURE CONTAINER*/
	/*$("#signatureContainer").mouseover(function(){
		$(this).stop().animate({'right':'0'},{queue:false, duration:500});										
	}).mouseout(function(){
		$(this).stop().animate({'right':'-176px'},{queue:false, duration:500});	
	});*/
	
	/*DESIGN JQTRANSFORM*/
	$('#search').removeClass('loader');
	$('#newsletterBox').removeClass('loader');
	$('#advancedSearchBox').css('display','none');
	
	//Define Width of inputs in Newsletter With jqtransform
	var myW = 292;
	var myWrapper = myW+18;
	$(".input1").css("width", myW);
	$(".input1").parents(".jqTransformInputWrapper").css("width", myWrapper);
	
	//Make Forms Visible
	$('form').css("visibility","visible");
	//LOAD JQTRANSFORM
	$('form').jqTransform({imgPath:'design/jqtransformplugin/'});
	
	$("#newsletterList .newsletterLine").click(function(event) {
		event.preventDefault();
		var str = $(this).find("a").attr("href");
		if(str.length > 0){
			window.open($(this).find("a").attr("href"), '_blank');
		}
	});
	/*SCROLL TO TOP*/
	//$().UItoTop({ containerID: "toTopLink", easingType: 'easeOutQuart' });
	
	/*VERTICAL ALIGN*/
	//$(".titleTextNews").vAlign();
	
	reinitialiseScroll();
	
	//resizeMap();
	// INITIALIZE TOOLTIP
	initializeTooltip();	

	// initialize scrollable and update numbers on top
	$(".scrollable").scrollable({
		onSeek: function(event, tabIndex) {
			var api = $(".scrollable").data("scrollable");
			numberActual = api.getIndex()+1;
			$(".pageActual").html(numberActual);
		}							
	});
	//Start Numbers of Scroll
	var api = $(".scrollable").data("scrollable");
	if(api){
		numberTotal = api.getItems().size();
		$(".pageTotal").html(numberTotal);
		numberActual = api.getIndex()+1;
		$(".pageActual").html(numberActual);
	}
	
	$(".submenuOpen").animate({'height':'show'});
	
	$(".newsArchive .newsForMonth a").live('click',function(){
		getNewsArchive(this);
	});
	$(".newsletterArchive .newsForMonth a").live('click',function(){
		getNewsletterArchive(this);
	});

	$("a.searchButton").click(function(){
		$("#searchBox").fadeIn();		
		$("#searchBox input").focus();
	});
	$("#searchBox #closeButton a").click(function(){
		$("#searchBox").fadeOut();			 
	});
	
	$(".closeUpponDiv").click(function(){	
		//$(".upponDiv").hide('slow');
		$(".upponDiv").fadeOut('slow');
	});
	$(".knowMoreMenuLink").click(function(){	
		/*$(".upponDiv").hide('slow');
		$(".upponDiv#tab-"+$(this).attr("id")).show('slow');*/
		
		
		$(".upponDiv#tab-"+$(this).attr("id")).stop().fadeIn('slow');
		$(".upponDiv").not("#tab-"+$(this).attr("id")).fadeOut('slow');
	});
	
	// INITIALIZE TOOLTIP NEWS
	$(".imageWinesPageContainer a img").tooltip({
		effect: 'slide'
	}).dynamic({ bottom: { direction: 'right', bounce: true } });
	
	$(".imageWineContainer a img").tooltip({
		effect: 'slide', 
		/*relative:true,*/ 
		cancelDefault:true,
		offset: [($("#content").height() > 800 ? 0 : -(50+$("#container").height()  * 0.1)), 0]
	});//.dynamic({ bottom: { direction: 'right', bounce: true } });
	//resizeScrollHeight();
	
	// List Nav
	$('#demoOne').listnav({
		includeAll: false,
		includeNums: false,
		includeOther: true,
		flagDisabled:true,
		noMatchText: noentries,
		showCounts:false,
		initLetter:location.hash.substr(1),
		onClick: function(letter){
		  $("#letter").html(letter);
		  document["location"].hash="#"+letter;
		}
	});
	if($('#demoOne').length > 0 && location.hash.substr(1))
	{
		$("#letter").html(location.hash.substr(1));
	}
	
	
	var interval = setInterval(function() {
		$("#content").animate({'right':0},500,"easeInOutBack", function(){ /*$(this).css( 'position','relative');*/ });
		clearInterval(interval);
	},1000);
	
});
$(window).resize(function(){ 
						  
	//resizeImgObjects()					  
	//$('.scrollPane').css("overflow","auto");
	//resizeScrollHeight();
	//resizeMap();
	//reinitialiseScroll();
	
});
$(window).bind('scroll', function(){

});


