//===========================================
// Name: El Matador Sports
// Description: 
// Version: 1.0
// Author: Jeremy Anderson [ Object Adjective ]
// Author URI: http://www.objectadjective.com
//===========================================

//Set ready state
$(document).ready(function(){
   $("head").append("<meta http-equiv='X-UA-Compatible' content='IE=7' />");
   
   //Clickable Feature Boxes on Homepage
   $(".box").bind("mouseenter mouseleave", function(e){
        $(this).toggleClass("hover");
		});
   $("#boxdesign").click(function(){
   		window.location = "product/index.htm?cat=design";
	});
   $("#boxfeature").click(function(){
   		window.location = "product/index.htm?cat=features";
	});
   $("#boxget").click(function(){
   		window.location = "contact/index.htm";
	});
   
   //Popup Divs
   $("#dim").click(function(){
   		closePopDiv();
	});
   $(".close").click(function(event){
   		closePopDiv();
		event.preventDefault();
	});
   $(".svw ul li img").click(function(){ //Triggers all img gallery pops
		var popdiv_show = $(this).attr("alt");  
		$("#"+popdiv_show).fadeIn('slow');
		popDiv();
	});
   $(".pop").click(function(event){ //Triggers all pops from 'a' with 'pop' class
		var popdiv_show = $(this).attr("href");  
		$(popdiv_show).fadeIn('slow');
		event.preventDefault();
		popDiv();
	});
   
   //Product Gallery Handlers
	$(".svw ul li img").bind("mouseenter mouseleave", function(e){
        $(".info-gal").toggleClass("hover");
		$(this).toggleClass("hover");
	});
	$(".next").click(function(event){
		event.preventDefault();
   		$(".current").parent().next("li").find("a").click();
	});
	$(".prev").click(function(event){
		event.preventDefault();
   		$(".current").parent().prev("li").find("a").click();
	});
	
	//Tabbed Content  
	$("a.tab").click(function (event) { 
	event.preventDefault();
	$(".active").removeClass("active");  
	$(this).addClass("active");  
	$(".tab-content").hide();  
	var content_show = $(this).attr("title");  
	$("#"+content_show).slideDown('slow');  
	});
	
	//Query (requires jquery.query.js)
	if(document.getElementById('bodyproduct') || document.getElementById('bodycontact')){
	var cat = $.query.get('cat');
	}
	if(cat == "design"){
		$("#design").slideDown('slow');
	}
	if(cat == "features"){
		$(".active").removeClass("active").next('a').addClass("active");
		$(".tab-content").hide();
		$("#features").slideDown('slow');
		
	}
	if(cat == "thankyou"){
		$("#thanks").fadeIn('slow');
		popDiv();
	}
	if(cat == "nogo"){
		$("#nogo").fadeIn('slow');
		popDiv();
	}
	
	
	//Pullquotes
	$('.pullquote').each(function() { $(this.parentNode).before('<div class="pullquote"><div class="mid"><h2>&quot;' + $(this).html() + '&quot;</h2></div><div class="bottom"></div></div>'); });
	
	//Form Field focus
	$("input, textarea, select").focus(function() {
		  $("input, textarea, select").removeClass("focus")
          $(this).addClass("focus");
 	 });
	// validate signup form on keyup and submit
	if(document.getElementById('bodycontact')){
	$("#contact").validate({
		rules: {
			name: "required",
			email: {
				required: true,
				email: true
			},
			comments: "required"
		},
		messages: {
			name: "Please enter your name.",
			email: "Please enter a valid email address.",
			comments: "Please enter your comments or inquiries."
		}
	});
	$(".submit").click(function(event) {
			$(this).parent().parent().submit();
			event.preventDefault();
		});
	}
   
 });

// This Controls Text on Homepage
//===========================================================================================


document.write("<style type='text/css'>\n" +  "#change {visibility:hidden;}\n" + "</style>");

//Total Number of text Phrases
var Txt = new Array()
Txt[1] = "Enhance your <strong>practice time.</strong>"
Txt[2] = "Get more out of <strong>your players</strong>"
Txt[3] = "introducing the <strong>El Matador Soccer Machine!</strong>"

function initS1() {
  dopacity();
  $("#change").html(Txt[1]);
  setS2();
}
function setS2(){ setTimeout("initS2()", 4000); }
  
function initS2() {
  dopacity();
  $("#change").html(Txt[2]);
  setS3();
}

function setS3(){ setTimeout("initS3()", 4000); }
 
function initS3() {
  dopacity();
  $("#change").html(Txt[3]);
}

function dopacity(){
  var imageId = 'change';
  var image = document.getElementById(imageId);
  image.style.visibility = 'visible';
  setOpacity(image, 0);
  fadeIn(imageId,0);
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 2;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 40);
    }
  }
}


//===========================================================================================

// POPUP DIVS

function popDiv() {
		getHeight();
		var browserName = navigator.appName;
		if(browserName == "Microsoft Internet Explorer"){
		$(".alert").css("top", document.documentElement.scrollTop+100+'px');
		}
		else {
		$(".alert").css("top", window.pageYOffset+100+'px');
		}
		$("#dim").show();
}

function closePopDiv(){
	$(".alert").fadeOut('slow');
	$("#dim").hide();
	return false;
}


// Dim Layer for POPUP DIVS

function getHeight(){
	if (parseInt(navigator.appVersion)>3) {
 		if (navigator.appName=="Netscape") {
  		wind = window.innerWidth;
  		wind = window.innerHeight;
 		}
 		if (navigator.appName.indexOf("Microsoft")!=-1) {
  		wind = document.body.offsetWidth;
  		wind = document.body.offsetHeight -136;
 		}
	}
	var divh = document.getElementById('wrapper').offsetHeight;
	var lock = document.getElementById('dim');
	if (divh >= wind){
	lock.style.height = divh +136+"px";
	}
	else {lock.style.height =wind +136+"px";}
}

//Below is code for the slide gallery on the product pages

jQuery(function(){
   jQuery("div.svw").prepend("<img src='../img/ajax-loader.gif' class='ldrgif' alt='loading...'/ >"); 
});
var j = 0;
jQuery.fn.slideView = function(settings) {
	  settings = jQuery.extend({
     easeFunc: "easeInOutExpo", /* <-- easing function names changed in jquery.easing.1.2.js */
     easeTime: 750,
     toolTip: false
  }, settings);
	return this.each(function(){
		var container = jQuery(this);
		container.find("img.ldrgif").remove(); // removes the preloader gif
		container.removeClass("svw").addClass("stripViewer");		
		var pictWidth = container.find("li").find("img").width();
		var pictHeight = container.find("li").find("img").height();
		var pictEls = container.find("li").size();
		var stripViewerWidth = pictWidth*pictEls;
		container.find("ul").css("width" , stripViewerWidth);	
		container.css("width" , pictWidth);
		container.css("height" , pictHeight);
		container.each(function(i) {
			jQuery(this).after("<div class='stripTransmitter' id='stripTransmitter" + j + "'><ul><\/ul><\/div>");
			jQuery(this).find("li").each(function(n) {
						jQuery("div#stripTransmitter" + j + " ul").append("<li><a title='" + jQuery(this).find("img").attr("alt") + "' href='#'>"+(n+1)+"<\/a><\/li>");												
				});
			jQuery("div#stripTransmitter" + j + " a").each(function(z) {
				jQuery(this).bind("click", function(){
				jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current"); // wow!
				var cnt = - (pictWidth*z);
				jQuery(this).parent().parent().parent().prev().find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
				return false;
				   });
				});
			jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
			jQuery("div#stripTransmitter" + j + " a:eq(0)").addClass("current");
			if(settings.toolTip){
			container.next(".stripTransmitter ul").find("a").Tooltip({
				track: true,
				delay: 0,
				showURL: false,
				showBody: false
				});
			}
			});
		j++;
  });
};




$(window).bind("load", function() {
	$("#productgallery").slideView();	//if leaved blank performs the default kind of animation (easeInOutExpo, 750)
	if(document.getElementById("change")){ initS1(); }
	});

