/*
Description: RTP
Author: Barnum Design
*/	

var $ = jQuery.noConflict();
$(document).ready(function(){
							
/////* Global variables */////
var Loc=document.location.href;
var breadcrumb=$('#catalog_crumb');
Dir0 = Loc.split('/')[3];
Dir1 = Loc.split('/')[4];
Dir2 = Loc.split('/')[5];
Dir3 = Loc.split('/')[6];
Uns1 = Loc.split('_')[1];
section="";
catalog="";
in_catalog=false;

/////* Templates */////
if(Dir0!="index.htm" && Dir0!="" && Dir0.substring(0,11)!="FormProcess"){ // all but the portal
$('.Top_nav').show();
$('.Top_crumb').show();
$('.Bottom .site-search').css('visibility','visible');
}

// Bottom banner
//if($('.page-body.sub-3').height()!=null)$('.Bottom .banner').show();

if($('.page-body.catalog').height()!=null){
$('.Top_trans').show();
in_catalog=true;
$('.Top_logo').show();
if(Dir1==null)section="tape";
}
if(Dir0=="products" || Dir0==""){

/* Products Flash accordion */
var flashvars={setupXML:"/flash/accordion-ft/settings.xml"};
var params={play:"true",loop:"false",scale:"noscale",salign:"tl",quality:"high",wmode:"transparent",allowfullscreen:"true",allowscriptaccess:"always"};
var attributes={};
swfobject.embedSWF("/flash/accordion-ft/accordion.swf","catalog_accordion","764","297","9.0.0",false,flashvars,params,attributes);
}

//// Catalog & product Detail class injections and reveal. 
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" || $('.page-body.catalog').height()!=null) {
$('.Wrap').addClass('catalog');
	if($('.page-body.catalog .productList.productSmall').height()!=null){
	$('.Wrap').addClass('prod-small');
	$('.page-body.catalog .cat_description').show();
	}
	if($('.page-body.catalog .productList.productLarge').height()!=null){
	$('.Wrap').addClass('prod-large');
	}
}

// breadcrumb
if($('.page-body.catalog').height()!=null || $('.page-body.shop-cart').height()!=null){
$('.Top_crumb span:first').html($('.breadcrumbs').html());
if($('.product-large').height()!=null)$('.Top_crumb span:first').append(" / "+$('.product-large .code:first').html());
$('.Top_crumb .products').show();
}
if(Dir0=="index.htm" || Dir0==""){
section="home";
// Flash embedd
/*
var flashvars={};
var params={play:"true",loop:"false",scale:"noscale",salign:"tl",quality:"high",wmode:"transparent",allowfullscreen:"true",allowscriptaccess:"always"};
var attributes={};
swfobject.embedSWF("/flash/banner.swf","intro_banner","675","250","9.0.0",false,flashvars,params,attributes);
*/
}

// Top banner - sub
else if(Dir0=="resources" || Dir2=="resources")section="resources";
else if(Dir0=="case-studies" || Dir2=="case-studies")section="case-studies";
else if(Dir1=="screen-printers")section="screen-printers";
else if(Dir1=="digital-printers")section="digital-printers";
else if(Dir1=="exhibits-displays")section="exhibits";
else if(Dir1=="login")section="login";
else if(Dir1=="sign-shops")section="sign-shops";
else if(Dir0=="about")section="about";
else if(Dir0=="products" && Dir1=="")section="products";
else if(Dir0=="contact")section="contact";
//else if(Dir1=="events" || Dir0.substring(0,20)=="AnnouncementRetrieve") section="events";
else section="about";
var banner_src= "/images/template/top/"+section+".jpg";
$('.Top_banner img').attr('src',banner_src);

// Top banner - catalog
switch(Dir0){
case "application-tapes": 
case "screen-printing": 
case "claritex": 
case "digimask":
case "eclypse":
case "prograde":
case "ez-erase":
case "vinylefx":
case "chalktalk":
case "sef-textiles":
case "flex-and-flock-films":

var logo_src= "/images/catalog/logos/"+Dir0+".png";
var logo_link= "/"+Dir0;
var banner_src= "/images/template/top/"+Dir0+".jpg";
$('.Top_banner img').attr('src',banner_src);
$('.Top_logo img').attr('src',logo_src);
$('.Top_logo a').attr('href',logo_link);
}

///// TDS page - Hide table rows with empty values.
$('.tech-data.detail .specs table td.value').each(function(){
if($(this).html()=="") $(this).parent().remove();
});

///// TDS page - Hide "section" classed wrappers with empty content.
$('.tech-data.detail .section').each(function(){
if($(this).find('li').eq(0).html()==null && $(this).find('table').eq(0).html()==null && ($(this).find('p').eq(0).html()=="" || $(this).find('p').eq(0).html()==null)) $(this).hide();
});

/// Catalog description - Hide and reveal copy with "Read More+" link
$('.cat_description .main p:first').siblings('p').hide();
$('.cat_description .main a.read-more').click(function(){
	$('.cat_description .main p:first').siblings('p').toggle('slow');
	return false;
});

// Product Detail 
function productDetail(){
	///// Catalog product detail - Hide empty fields in "ul.cols" list-items
	$('.page-body.catalog .productLarge ul.cols li').each(function(){
	if($(this).children('p').eq(0).html()=="") $(this).hide();
	});
	///// Catalog product detail - Change Tech Data link names to "Tech Data".
	$('.product-large .tech-data a').html('Tech Data');
	///// Hide ".bottom" div if no related products are present.
	if($('.product-large .bottom table.productTable').html()==null) $('.product-large .bottom').hide();
}
productDetail();
// Reset productDetail() function when "Add To Quote" button is clicked.
$('.product-large .add-to-quote input').click(function(){productDetail();});

///// Fancy Box 
$('.page-body.distributors-locator .map-it a').addClass('ltbx if');

$('a.ltbx').fancybox({'transitionIn':'elastic','transitionOut':'elastic','speedIn':600,'speedOut':200,'overlayShow':true});
$('a.ltbx a').fancybox({'transitionIn':'elastic','transitionOut':'elastic','speedIn':600,'speedOut':200,'overlayShow':true});
$('a.ltbx.win').fancybox({'width':575,'height':'auto','autoDimensions':false});
$("a.ltbx.if").fancybox({'width':'75%','height':'75%','autoScale':false,'transitionIn':'none','transitionOut':'none','type':'iframe'});

//// Nav
$('.s-nav a').each(function(){;
var SubA=$(this);
var SubL=this.href;
var sHsh = SubL.split('#')[1];
var sDir0 = SubL.split('/')[3];
var sDir1 = SubL.split('/')[4];

//var pArt = SubA.parents('ul').prev('a').attr('href').split('/')[1];
	if (((SubL==Loc || SubL==Loc.substring(0,Loc.length-1)) && sHsh==null) || SubA.html()==breadcrumb.html() || sDir1=="tech-data" && $('.page-body.resources.tech-data').height()!=null || sDir1=="distributors-locator" && $('.page-body.distributors-locator').height()!=null || ($('#Account')!=null && (sDir0=="Account" && sDir1=="") || (Dir0=="announcements" && (sDir1=="press" || sDir1=="events")) || (Dir0=="_webapp_1212928" && sDir1=="tech-data") || (Dir1=="tips" && sDir1=="tips") || (Dir0.substring(0,12)=="CaseRetrieve" && sDir1=="Case_History.htm") || (sDir0=="products" && sDir1=="" && (in_catalog==true || Dir0=="products" || Dir0.substring(0,13)=="OrderRetrieve")) || (Dir0.substring(0,19) == "OrderSecureRetrieve" && sDir1 == "Order_History.htm")) || (sDir0=="Store" && (Uns1=="catalog" || Loc.split('_')[1]=="product" || Dir0.substring(0,13)=="OrderRetrieve" || Dir0.substring(0,17)=="CatalogueRetrieve")) || (sDir1== "FAQs.htm" && (Dir0.substring(0,11)=="FAQRetrieve" || Dir0.substring(15,18)=="FAQ"))) {
	$(this).addClass('active');
	$(this).parents('li').addClass('selected');
	$(this).parents('ul').addClass('selected');
		if($(this).siblings('ul').eq(0).height()!=null) $(this).siblings('ul').eq(0).addClass('active');
		else if ($(this).parents('ul').eq(1).height()!=null) $(this).parents('ul').eq(0).addClass('active');
	}
});

///// SZ Login Nav
if(loggedin==1){
$('.loggedIn').css('display', 'block'); 
}
else {
$('.loggedOut').css('display', 'block');
}

///// Nav hover
$('#TopNav > div > ul > li ').mouseover(function(){
$(this).siblings().removeClass('selected');
$(this).addClass('selected');
 $(this).mouseleave(function(){
 $(this).removeClass('selected');
 });
});

///// List stripe
$('ul.stripes.odd li:odd[display!="none"]').addClass('stripe');
$('ul.stripes.even li:even[display!="none"]').addClass('stripe');
$('table.stripes.odd tr:odd[display!="none"]').addClass('stripe');
$('table.stripes.even tr:even[display!="none"]').addClass('stripe');

///// Distributors locatior - "State" select display
/*
$('.webForm.locations select.country').change(function(){
	$('.webForm.locations select.state').hide();
	//$('.webForm.locations select.state').each(function(){
		//$(this).children('option:first').attr('selected','selected')
	//});
	var stateSelect = '.webForm.locations select.state.' + $(this).children('option:selected').attr('value');
	$(stateSelect).siblings().children('option:first').attr('selected','selected');
	$(stateSelect).show();
});
$('.webForm.locations select.country').change();
*/

///// Distributors locator - hide blank elements
$('.page-body.distributors-locator .results ul.details li').each(function(){
	if($(this).children('span').eq(0).html()=="") $(this).hide();
});

///// Portal Body Nav hover
$('.page-body.portal .col').mouseenter(function(){
$(this).find('div.bg').eq(0).animate({left:"0px"},700);
$(this).find('img').eq(0).animate({left:"0px"},700);
$(this).find('ul').eq(0).animate({opacity:"1.0"},700);
});
$('.page-body.portal .col').mouseleave(function(){
$(this).find('div.bg').eq(0).stop(true,false).animate({left:"-190px"},700);
$(this).find('img').eq(0).stop(true,false).animate({left:"-190px"},700);
$(this).find('ul').eq(0).stop(true,false).animate({opacity:"0.0"},700);
});

///// Quicksand id injections
$('ul.productList.productSmall').attr('id','dataList');
prod_count = 1;
$('ul.productList.productSmall span.title').each(function(){
	var prod_title = $(this).text().toLowerCase().replace(/\s/g ,'-');;
	$(this).parents('li').addClass(prod_title).attr('data-id',('id-'+prod_count));
	prod_count ++;
});

});

//// 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($('#gMap_addr').html()!=null){
var gMap_address=$("#gMap_addr").html();
var gMap_title=$("#gMap_title").html();
initialize();
showAddress(gMap_address,gMap_title);
$('#map_canvas').parent().hide();
}


