/*

	Switch Interactive
	http://www.switchinteractive.com
    
	Design and Code : Switch Interactive
	Author Homepage : http://www.switchinteractive.com	
	Created : January 20th 2010
	Last Updated : January 20th 2010

	Notes: Temporary Blog
	
*/
$(document).ready(function() {
				
		var currItem;
		var isGoogleMap = false;
		var start = true;
		$("body").addClass("js");
		// CUFON REPLACEMENT
		Cufon.replace('h2',{hover: true});	
		Cufon.replace('h3');		
		
		
 	 	$(".close").click(function() {
				$(".close").parent().slideUp(500); 
				$("#topmenu A").removeClass('selected'); 
				currItem = -1;
				}); 
	
	
		$("#topmenu A").click(function (e) {
			var pageName = $(this).attr("rel");
			if (pageName == "Blog") return;
			if (pageName == "home") return;
				
			e.preventDefault();
			var index = $("#topmenu A").index(this);
			index = index-1;
     		menuswap(index,$(this).attr("rel"));	
		});
		
		var count = 0;
		
		var totest = String(window.location).split("switchunited.com/")[1].charAt(0);
		$("#topmenu A").each(function(id) {
			if(String(window.location).search("blog") > -1) {
				if("/"+$(this).attr("rel") == SWFAddress.getValue()) menuswap(count - 1, $(this).attr("rel"));				
			} else if(totest == "#" || totest == "") {
				if("/"+$(this).attr("rel") == SWFAddress.getValue()) {
					if(SWFAddress.getValue() != "/about") menuswap(count - 1, $(this).attr("rel"));
				}
			} else {
				if("/"+$(this).attr("rel") == SWFAddress.getValue()) menuswap(count - 1, $(this).attr("rel"));
			}
			count++;
		});
		if((SWFAddress.getValue() == "/about" || SWFAddress.getValue() == "/") && String(window.location).search("blog") < 0 && (totest == "#" || totest == "" || totest == $("#topmenu A:eq(0)").attr("href"))) {
			menuswap(0, "about");
		}


	function menuswap(index, rel){
		
		$(".info").slideUp(); //hide sections
		if(currItem != index) {
			$(".info").eq(index).slideDown(); //show active	
		}
		else {	
			$("#topmenu A").removeClass('selected'); 
			index = -2;
		}
		currItem = index;
		var uagent = navigator.userAgent.toLowerCase();
		 if (uagent.search("iphone") < 0 && uagent.search("ipod") < 0 && uagent.search("ipad") < 0) {
			 if(start == false) SWFAddress.setValue(rel);
				
		 }
		start = false;
		if(rel == "contact" && !isGoogleMap) {
			if(uagent.search("iphone") < 0 && uagent.search("ipod") < 0 && uagent.search("ipad") < 0) $("#gmap").html("<iframe width='265' height='240' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=128+west+8th+vancouver&amp;sll=37.0625,-95.677068&amp;sspn=54.753001,118.388672&amp;ie=UTF8&amp;hq=&amp;hnear=128+W+8th+Ave,+Vancouver,+Greater+Vancouver+Regional+District,+British+Columbia,+Canada&amp;ll=49.263912,-123.108115&amp;spn=0.003361,0.006845&amp;z=16&amp;iwloc=near&amp;output=embed'></iframe><br /></div>");
			
			isGoogleMap = true;
		}
		
		$("#topmenu A").removeClass('selected'); 	
		index=index+1
		if(index > -1) $("#topmenu A").eq(index).addClass('selected'); 
		}
		
	
		// redefine Cycle's updateActivePagerLink function 
		$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
			$(pager).find('li').removeClass('selected') 
				.filter('li:eq('+currSlideIndex+')').addClass('selected'); 
		}; 
		
		function handleChange(e) {
			
		}

		$('.pager').cycle({
			prev:   '#prev', 
			next:   '#next', 
			timeout:       	0,  // milliseconds between slide transitions (0 to disable auto advance) 
			speed:         1500,  // speed of the transition (any valid fx speed value) 
			pause:         1,     // true to enable "pause on hover" 
			delay:       	0,     // additional delay (in ms) for first transition (hint: can be negative) 
			fx:					'scrollHorz',
			pager:			 '#feature-pagination',
			pagerAnchorBuilder: function(idx, slide) { 
				idx = idx +1; // Kill the 0				
     			   return '<li><a href="#" class="feature-button goto'+idx+'">'+idx+'</a></li>'; 
   				 } 
			});
		
		});
		
		
		
