/*
PHfunctions.js
compiled 1.3.11
relys on:
../JS/jqUI/js/jquery-1.4.2.min.js
../JS/jqUI/js/jquery-ui-1.8.6.custom.min.js"


*/








// cl 
// 12.10 creation - several rounds of tab scripts
// essentially a stripped down jqueryui tab
// 1.3.11 moved to external file
// 1.6 nested tabs added
// 1.19 modal section for install page and wa stuff

$(document).ready(function() {

	
// Tabs
$('#tabs').tabs();


$('.tabz').tabs();


/*modify the url 
// compliments of http://insideria.com/2009/03/playing-with-jquery-tabs.html
// keeping this block also activates 'tab history' 
// if we want it.....
$("#tabs").bind('tabsselect', function(event, ui) {
	document.location='#'+(ui.panel.id);
	
});
// url
*/


//getter for linking into a tab				
if(document.location.hash!='') {
	   indexToLoad = document.location.hash;
 	  $("#tabs").tabs('select',indexToLoad);
}				

$('a.directTab').click( function(){
    var tabWanted = $(this).attr('rel').split('-')[0];
	var tabWanted2 = $(this).attr('rel').split('-')[1];
	$('#tabs').tabs( "select" , tabWanted);
	$('.tabz').tabs( "select" , tabWanted2);
	return false;
    });
// use like this: <a href="#" class="directTab" rel="Options-graphics">View Custom Graphics</a>

	




/*
swapper.js
Controls image swapping for Images tab.
mostly coppied from WA.js
changelog
12.27.10 file creation dv
	added alt and title features (copy this to WA.js)

*/



//starts images thumbnails clicky
$('.ProductImageThumbs').each(function(index) {

var parent = "#" + $(this).parents('li').attr('id');
var visiblePic = $("li"+parent+" li.thumb a:first").attr('href');
var text = $("li"+parent+" li.thumb a:first").children('img').attr('alt');
var title = $("li"+parent+" li.thumb a:first").children('img').attr('title');



$("li"+parent+" #bigone").attr('src', visiblePic);
$("li"+parent+" #description").html(text);
$("li"+parent+" #title").html(title);

$('li.thumb a').mouseover(function(){

var parent2 = "#" + $(this).parents('li.tab_content').attr('id');
$("li"+parent2+" #bigone").hide();

var image = $(this).attr('href');

var newtext = $(this).children('img').attr('alt');
var newtitle = $(this).children('img').attr('title');

$("li"+parent2+" #bigone").attr('src', image);
$("li"+parent2+" #description").html(newtext);
$("li"+parent2+" #title").html(newtitle);

$("li"+parent2+" #bigone").delay(300).fadeIn(300);
return false;
});

});

$('li.thumb a').click(function(){
return false;
});
//ends images thumbnails clicky




// function swapImages must reside outside of doc.ready (?)
// so we stop it here
 });

/*
starts new fader
*/


//core function for fader  
    function swapImages(){

var $activeicon = $('.fadecontrols a.active');

      var $active = $('#fader .visible');
      var $next = ($('#fader .visible').next('img').length > 0) ? $('#fader .visible').next('img') : $('#fader img:first');
	  $next.fadeIn().addClass('visible');
	  
      $active.fadeOut(function(){
	  $active.removeClass('visible');


$activeicon.removeClass('active');


//get index of active image
  var visibleimage = $("#fader .visible").index();
//find control with same index & mark it
  $(".fadecontrols a.selectme:eq(" + visibleimage + ")").addClass('active');

	  
      });
	 
	 
    }	 
  
  


// function swapImages must reside outside of doc.ready (?)
// so we start it here
$(document).ready(function(){
	
	
	$('.play').hide();	
// Run our swapImages() function every 5secs
goSwap = setInterval('swapImages()', 5000);
//play action	 
$(".play").click(function(){	 
	 goSwap = setInterval('swapImages()', 5000);
	$(this).hide();
	$('.stop').css("display","block");
 } ); 	 
//stop action	 
$(".stop").click(function(){	 
	 clearInterval ( goSwap );
	$(this).hide();
	$('.play').css("display","block");
 } ); 

//control with a
  $(".fadecontrols a.selectme").click(function(){
// stop autoplay
clearInterval ( goSwap );
//hide stop and show play
	$('.stop').hide();
	$('.play').css("display","block");

//get current image
  var $active = $('#fader .visible');
// fade out current image and remove class
     $active.fadeOut(function(){
     $active.removeClass('visible');
      
     });


//get index of clicked span
  var index = $(".fadecontrols .selectme").index(this);

//find image with same index & show it
  $("#fader img:eq(" + index + ")").fadeIn().addClass('visible');

//finally add active class to the span
$(".fadecontrols a.active").removeClass('active');
$(this).addClass('active');  
  
  });
 
	 
/*
end new fader


starts navigation
*/	 


// cl 
// 12.10 creation - activates parent(s) of link to current page
// 12/29 moved to external file
// 1/4/11 compiled to phfunctions
// 2/3ish  modified for installation/59t issues
// 2/9 exploding navigation hacked


$(".second-level").hide();
$(".third-level").hide();



// get the document path and search for it

var loc = window.location;

var hash = loc.search;
var str2 = "load";
//filter out the search string if we're at the installation gallery
if(hash.indexOf(str2) != -1){
    var thispage = loc.pathname; 
}

else  { 
var thispage = loc.pathname+loc.search; 
} 

$(".top-level li").find("a[href='"+thispage+"']").each(function(){
	
	
																				
	$(this).addClass('active');
	//flag parent li as active
	var parent = $(this).parents('li');
	$(parent).addClass('active');
	
		var parent2 = $(this).parents('li.section');
		$(parent2).removeClass('section').addClass('section-active');
		
	//show any siblings
	var sibs = $(this).parents('ul');
	$(sibs).show().addClass('active');
	//show any children
    $(this).next('ul').show();
	
});




						 
$(".top-level li:has(ul)").prepend('<div class="more"> + </div>').prepend('<div class="less"> - </div>');					 
$("div.less").hide();
$("li.active").children('.more').hide();

//:eq(2)
$("div.more").click(function(){
		
	$(this).siblings('.second-level, .third-level').show('fast',function(){
																		 
												if($.browser.msie) {$(this).get(0).style.removeAttribute('filter');}

																		 
																		 });
	var moreparent = $(this).parent('li');	
	$(moreparent).children('.less').show();
	$(this).hide();
	$(moreparent).addClass('expanded');
    });

$("div.less").click(function(){
							  
	$(this).siblings('.second-level, .third-level').hide();	
	var expandedparent = $(this).parent('li.expanded');	
	$(expandedparent).children('.more').show();
	$(expandedparent).removeClass('expanded');
	$(this).hide();
	  
    });





// ends navigation



//starts installation modals
$( ".modalme" ).hide();
$( ".modalme" ).dialog({
			autoOpen: false,
			height: 630,
			width: 840,
			modal: true
					  });
str = window.location.search;
if (str.indexOf("load") === -1) 
 {
// alert('not found');
 } else
{
  	$('.modalme').dialog( "open" );
}
//ends installation modals





//featured modal animation
$( "#modal_video" ).hide();
$( "#modal_video" ).dialog({
			autoOpen: false,
			height: 540,
			width: 800,
			modal: true
					  });

$('#play_featured').click(function(){
  	$('#modal_video').dialog( "open" );
});



/*
WA.js
Controls scrolling thumbnails and image swapping for
wilsonart laminate sample page. .

changelog
12.9.10 file creation dv
1.12.11 quickship addition 
1.18.11 added displaying the current image name and paging location for WAthumbs
1.18.11 copied function for stool swapper
1.19 should be done, brought into phfunctions
*/


// initialize scrollable 
window.api = $(".scrollable").scrollable({ circular: false, vertical: true, api: 'true' });	




	
//adjust math to suit the number of thumbnails to show	
var showthismany = 9;
	
$('.previous').click(function(){	api.move(-showthismany, 400); });
$('.nexxt').click(function(){	api.move(showthismany, 400); });	
	
	
//hide previous button
$('.previous').hide();

var total = $(".WAthumb").length;
// this is total or 1 less than total possibly displayed
var maxpage = total - showthismany;

var pages = Math.ceil(total/showthismany);
$('.end').html(pages);


	$('#actions').click(function(){
	var position =	api.getIndex();
//	alert(position);
	if(position == '0') { $('.previous').hide(); 	} else {$('.previous').show();}
	if(position >= maxpage) { $('.nexxt').hide(); 	} else {$('.nexxt').show();}
	
var here = Math.ceil((position+1)/showthismany);
$('.start').html(here);	
	});
	
//ends scrollable	
	
	
	
//starts WA thumbnails clicky
var visiblePic2 = $("li.WAthumb img:first").attr('src');
$("#sample").attr('src', visiblePic2);

$('li.WAthumb a').mouseover(function(){

$("#sample").hide();
visiblePic2 = $(this).children('img').attr('src');

current = $(this).children('span').html();
alt = $(this).children('img').attr('alt');
$(".WAcurrentsample").html(current + ' - ' + alt);

$("#sample").attr('src', visiblePic2);
$("#sample").delay(100).fadeIn(300);
return false;

});
$('li.WAthumb a').click(function(){
return false;
});
//ends WA thumbnails cliky




//starts QS thumbnails clicky
var visiblePic3 = $("li.QSthumb img:first").attr('src');
$("#QSsample").attr('src', visiblePic3);

$('li.QSthumb a').mouseover(function(){

$("#QSsample").hide();
visiblePic3 = $(this).children('img').attr('src');

current = $(this).children('span').html();
alt = $(this).children('img').attr('alt');
$(".QScurrentsample").html(current + ' - ' + alt);

$("#QSsample").attr('src', visiblePic3);
$("#QSsample").delay(100).fadeIn(300);
return false;

});
$('li.QSthumb a').click(function(){
return false;
});
//ends QS thumbnails cliky








//gonna add the stools here too

var visiblePic4 = $("li.STthumb a:first").attr('href');
$("#STsample").attr('src', visiblePic4);

$('li.STthumb a').mouseover(function(){

//$("#STsample").hide();
visiblePic4 = $(this).attr('href');

current = $(this).children('span.name').html();

$(".STcurrentsample").html(current);

$("#STsample").attr('src', visiblePic4);
//$("#STsample").delay(100).fadeIn(300);
return false;

});
$('li.STthumb a').click(function(){
return false;
});

// ends stools 








// ends wilsonart block













// misc junk

// fixes product spects lists spacing
$("#Specs ul.specs li:odd").addClass('odd');
$("#Specs ul.specs li:even").addClass('even');
var lastone = $("#Specs ul.specs li:last").attr('class');
if (lastone == 'odd') { $("#Specs ul.specs").append("<li class='spacer'> </li>"); }
else {  $("#Specs ul.specs li:last").addClass('lastlink-even'); }




// clear the 4th ul .three-column
$("#specifications ul.three-column:eq(3), #specifications ul.three-column:eq(6)").addClass('clear');

$("#instructions ul.three-column:eq(3), #instructions ul.three-column:eq(6)").addClass('clear');







// search for laminates page...
$('#SearchSubmit').click(function(){
$('.missing_search_term').hide();
var theval = $('#search').val();
if(theval == '') { $('#SearchSubmit').after('<span class="missing_search_term">Please enter a search term</span>'); return false; }

});






 });
//thats all folks
