/*
Description: Ellman Family Vineyards
Author: Barnum Design
*/	

/// ----------------------------------- jQuery
var $j = jQuery.noConflict();
$j(document).ready(function(){
							
/////* Global variables */////
var Loc=document.location.href;
var breadcrumb=$j('#catalog_crumb');
var Dir0 = Loc.split('/')[3];
var Dir1 = Loc.split('/')[4];
var Dir2 = Loc.split('/')[5];
var Dir3 = Loc.split('/')[6];
var Uns1 = Loc.split('_')[1];
var section;

/////* Templates */////
if(Dir1!="index.htm" && Dir1!=""){ // all but the portal
}
if(Uns1!="catalog" && Dir1!="index.htm" && Dir1!="") $j('#Top .breadcrumb .main').fadeIn('1000');
if(Dir0.substring(0,17)=="CatalogueRetrieve" || Uns1=="product" || Uns1=="catalog" || Dir0.substring(0,15)=="OrderRetrievev2" || Dir0.substring(0,13)=="OrderRetrieve" || Dir0.substring(0,12)=="Default.aspx" || Dir0.substring(0,13)=="MemberProcess") {
$j('#Wrap').addClass('catalog');
	if(Uns1=="catalog"){
	$j('#Wrap').addClass('prod-small');
	$j('.page-body.shop-main .bottom').show('slow');
	}
	if(Uns1=="product"){
	$j('#Wrap').addClass('prod-large');
	}
}
else if(Dir1=="index.htm" || Dir1==""){
section="home";
}
else if(Dir1=="Products" && (Dir2=="" || Dir2=="index.htm")){
section="Products";
}
else if(Dir1=="About" && (Dir2=="" || Dir2=="index.htm")){
section="About";
}
else if(Dir1=="Events" || Dir0.substring(0,20)=="AnnouncementRetrieve"){
section="Events";
}
else{ 
section="default";
}

///// Fancy Box 
$j('a.ltbx').fancybox({'transitionIn':'elastic','transitionOut':'elastic','speedIn':600,'speedOut':200,'overlayShow':true});
$j('.ltbx a').fancybox({'transitionIn':'elastic','transitionOut':'elastic','speedIn':600,'speedOut':200,'overlayShow':true});
$j('a.ltbx.win').fancybox({'width':600,'height':600,'autoDimensions':false});
$j("a.ltbx.if").fancybox({'width':'75%','height':'75%','autoScale':false,'transitionIn':'none','transitionOut':'none','type':'iframe'});

///// Reisizr 
$j(".resizr img").each(function(){$j(this).cjObjectScaler({method:"fit",fade: 800});});

///// Nav
$j('.s-nav a').each(function(){;
var SubA=$j(this);
var SubL=this.href;
	if (SubL==Loc || (SubL.split('/')[3]==Loc.split('/')[3] && SubL.split('/')[4]=="") || SubA.html()==breadcrumb.html() || ($j('#Account')!=null && (SubL.split('/')[3]=="Account" && SubL.split('/')[4]=="") || (Loc.split('/')[3].substring(0,12)=="CaseRetrieve" && SubL.split('/')[4]=="Case_History.htm") || (Loc.split('/')[3].substring(0,19) == "OrderSecureRetrieve" && SubL.split('/')[4] == "Order_History.htm")) || (SubL.split('/')[3]=="Store" && (Loc.split('_')[1]=="catalog" || Loc.split('_')[1]=="product" || Loc.split('/')[3].substring(0,13)=="OrderRetrieve" || Loc.split('/')[3].substring(0,17)=="CatalogueRetrieve")) || (SubL.split('/')[4]== "FAQs.htm" && (Loc.split('/')[3].substring(0,11)=="FAQRetrieve" || Loc.split('/')[3].substring(15,18)=="FAQ"))) {
	$j(this).attr('class', 'active');
	$j(this).parents('li').attr('class', 'selected')
	}
});


///// jQuery UI Accordion (Our Team Page)
$j( "#accordion-founders" ).accordion();
$j( "#accordion-team" ).accordion();



/*
var opendate = new Date();
opendate.setMonth(1);
opendate.setDate(15);
opendate.setHours(12);
opendate.setMinutes(0);
opendate.setSeconds(0);

$j('#OrderCountdown').countdown({
	startTime: opendate,
    stepTime: 1,
    digitImages: 6,
    digitWidth: 53,
    digitHeight: 77,
    image: "/images/plugin/countdown/digits_inverted.png"
});
*/



///// SZ Login Nav
if(loggedin==1){
$j('.loggedIn').css('display', 'block'); 
}
else {
$j('.loggedOut').css('display', 'block');
}

///// IE6 
if(ie6==true){
//// Trans bg
$j('.trans').each(function(){$j(this).height($j(this).parent().outerHeight());});
}

///// Forced quantity discount
if ($j('table.cart .sub-total .quantity span').html()>=12){
var discountcode="PD2010";
$j('table.cart tr.discount input.discountcodeInput').attr('value',discountcode).trigger("change");
//ApplyDiscountCode(discountcode,1516922,35155);return false;
//return false;
}

///// Product out of stock
$j('.shop-main .details .instock').each(function(){
	if($j(this).html()==0){
	$j(this).parents('.shop-product-large').addClass('sold-out');
	$j(this).parents('.shop-product-small').addClass('sold-out');
	}
});

//// Wine taste page tabbing
$j(".page-body.taste .page.active").fadeIn('slow');
$j(".page-body.taste h2 span").click(function() {
	if($j(this).hasClass('active')) return;
	else {
	group=$j(this).attr('class');
	$j(".page-body.taste h2 span.active").removeClass("active");
	$j(".page-body.taste .page.active").fadeOut('fast').removeClass("active");
	$j(this).addClass("active");
	$j(".page."+group).addClass("active");
	setTimeout("$j('.page-body.taste .page.active').fadeIn('slow')", 300);
	}
});

//// Google map
var map = null;	
var geocoder = null;	
function initialize() {	
	if (GBrowserIsCompatible()) {	
	map = new GMap2(document.getElementById("map_canvas"));	
	map.setCenter(new GLatLng(-30.4693, 150.0179), 13);	
	map.addControl(new GLargeMapControl());	
	map.addControl(new GMapTypeControl());	
	geocoder = new GClientGeocoder();	
	}}	
	function showAddress(address,title) {	
	if (geocoder) {	
	geocoder.getLatLng(	
	address,	
	function(point) {	
	if (!point) {	
	alert(address + " not found");	
	} else {	
	map.setCenter(point, 13);	
	var marker = new GMarker(point);	
	map.addOverlay(marker);	
	marker.openInfoWindowHtml(title+"<br />"+address);	
	}});}}

//// Google map - custom address targetting
if($j('#gMap_addr').html()!=null){
var gMap_address=$j("#gMap_addr").html();
var gMap_title=$j("#gMap_title").html();
initialize();
showAddress(gMap_address,gMap_title);
$j('#Wrap #map_canvas').parent().hide();
}

});






//// ----------------------------------- Mootools

window.addEvent('domready', function() {	
									 
//// Taste page									 
var myAccordion = new Accordion($('accordion'), '.page-body.taste span.view', '.page-body.taste div.body', {
opacity: false,
show: true,
	onActive: function(toggler, element){
	toggler.setStyle('opacity', '0.0');
	},
	onBackground: function(toggler, element){
	toggler.setStyle('opacity', '1.0');
	}
});

});


