﻿$(document).ready(function() {
	//Equal Heights
	$(".eqheight").equalHeights(700);
	//loadData(1);
	
	
	$('#inpSearch').click(function() {
		$(this).val("");
		
	});
	
	/******************************************
	* Product listing viewMore div fading
	*******************************************	*/
	
	// OPACITY OF BUTTON SET TO 50%
	$("#footer .colmarg,.prod_button,#infoButton,.plspCategory li").css("opacity","0.6");
	//$(".col220").bind("load",fadeIt);
	
	/*function fadeIt(){
		alert("hej");
		$(".prod_button,#infoButton,.plspCategory li").css("opacity","0.6");
		}*/
	
	$("#footer .colmarg,.prod_button,#infoButton,.plspCategory li").live({
  mouseover: function() {
   $(this).stop().animate({
	opacity: 1.0
	}, "slow");
  },
  mouseout: function() {
   $(this).stop().animate({
	opacity: 0.6
	}, "slow");
  }
});

	/******************************************
	* Product listing ViewVideo fading
	*******************************************	*/
	
	// OPACITY OF BUTTON SET TO 50%
	$(".viewMore_video").css("opacity","0.5");
	//$(".col220").bind("load",fadeIt);
	
	/*function fadeIt(){
		alert("hej");
		$(".prod_button,#infoButton,.plspCategory li").css("opacity","0.6");
		}*/
	
	$(".viewMore_video").live({
  mouseover: function() {
   $(this).stop().animate({
	opacity: 1.0
	}, "slow");
  },
  mouseout: function() {
   $(this).stop().animate({
	opacity: 0.5
	}, "slow");
  }
});
	

	
	
	/******************************************
	* Category Images fadein color from BW
	*******************************************	*/	
	$("img.a").hover(
	function() {
	$(this).stop().animate({"opacity": "0"}, 1000);
	},
	function() {
	$(this).stop().animate({"opacity": "1"}, 700);
	});
	
	/******************************************
	* Activate Modal Window
	*******************************************	*/	
	$('.viewMore_image').live("click",function(e) {

        e.preventDefault();
        var imgSrc=$(this).attr("rel");
        
       // $("#myModalInner").html('<img src="'+imgSrc+'" />')
       $("#myModalInner").html("Loading...");
      // alert("loading");
       $("#myModal").css("background-color","#000");
       $("#myModal").css("border","2px solid #777");
			$("#myModalInner").load("index.php?id=7&product_ID="+imgSrc+" #content");
		$('#myModal').reveal();
    });
    
    /******************************************
	* View Product List Video in Modal Window
	*******************************************	*/	
	$('.viewMore_video').live("click",function(e) {

        e.preventDefault();
        var videoSrc=$(this).attr("href");
        
        $("#myModalInner").html('<iframe width="460" height="257" src="http://www.youtube.com/embed/'+videoSrc+'?rel=0" frameborder="0" allowfullscreen></iframe>')
		$('#myModal').reveal();
		
    });
    
    /******************************************
	* View Facebook Img in Modal Window
	*******************************************	*/	
	$('.fbStatus .fbViewImg').live("click",function(e) {

        e.preventDefault();
        var imgSrc=$(this).attr("href");
        
        $("#myModalInner").html("<img src='"+imgSrc+"' />");
		$('#myModal').reveal();
		
    });
    
    /******************************************
	* View Facebook Video in Modal Window
	*******************************************	*/	
	$('.fbStatus .fbViewVid').live("click",function(e) {

        e.preventDefault();
        var videoSrc=$(this).attr("href");
        $("#myModalInner").html('<iframe width="460" height="257" src="'+videoSrc+'" frameborder="0" allowfullscreen></iframe>')
        
		$('#myModal').reveal();
		return false;
    });
    
  /******************************************
	* Image Slider
	*******************************************	*/
	
	//Show Banner
	//$(".main_image .desc").hide(); //Show Banner
	//$(".main_image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity
 
	//Click and Hover events for thumbnail list
	$("#sppThumbs ul li:first").addClass('active'); 
	$("#sppThumbs ul li").live("click",function(){
		$("#sppVideo").fadeOut();
		$("#sppVideo").html("");
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		$("#sppImageSlider").fadeOut("100",function(){
				
				$("#sppImageSlider").html("<img src="+imgTitle+" />").fadeIn("200");
			});
		//Set Variables
		//var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
//var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		//var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
		//var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block	
		
		
			//Animate the Teaser
			//	alert("weareher");
				//$("#sppImageSlider").fadeOut();
				//$("#sppImageSlider").html("Loading..").fadeIn(); 
//$("#sppImageSlider").html("<img src="+imgTitle+" />").fadeIn(1000);
			//	alert (imgTitle);
				//$("#sppImageSlider").fadeIn();
					
			/*$("#sppImageSlider").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
			//	$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
				//$("#sppImageSlider img").attr({ src: imgTitle , alt: imgAlt});
				alert (imgTitle);
				$("#sppImageSlider").html("<img src="+imgTitle+" />");
			});*/
		
		
		$("#sppThumbs ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		
		return false;
		
	}) .hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});
			
	//Toggle Teaser
	$("a.collapse").click(function(){
		$(".main_image .block").slideToggle();
		$("a.collapse").toggleClass("show");
	});

	/******************************************
	* Replace Image DIV with Youtube IFRAME
	*******************************************	*/	
	$("#viewVideo").live("click", showVideo);
	function showVideo() {
		$("#sppThumbs ul li").removeClass('active'); //Remove class of 'active' on all lists
	$("#sppImageSlider").fadeOut();
	var videoUrl=$("#viewVideo").attr("rel");
	
	var videoIframe="<iframe width='460' height='257' src='http://www.youtube.com/embed/"+videoUrl+"?rel=0' frameborder='0' allowfullscreen></iframe>";
	
	$("#sppVideo").html(videoIframe);
	$("#sppVideo").fadeIn();
 
    };
    
  /******************************************
	* Product Search Bar 
	*******************************************	*/
	$("#selSortOrder").live("change", productSortOrder);
	function productSortOrder() {
		var howToSearch=$('#selSortOrder option:selected').val();
		var whatToSearch=$('#selSortOrder').attr("class");
		var typeToSearch=$(this).attr("rel");
		
		dataString="sortOption="+howToSearch+"&whatToSearch="+whatToSearch+"&typeToSearch="+typeToSearch+"&page=1";
		
		loadData(dataString);
		/*$.ajax({
				type: "POST",
				url: "index.php?id=9",
				data: dataString,
				cache: false,
				success: function(html){
				    $("#content").hide();
					$("#content").html(html);
					$("#selSortOrder option:selected").text(howToSearch);
					$("#content").fadeIn();
				}
			});
			return false*/
	}
	
	/******************************************
	* Search Products Field
	*******************************************	*/
	$("#inpSearch").live("keyup", headerSearch);
	
	
	$('#inpSearchDisplay').mouseleave(function() {
		
  		$("#inpSearchDisplay").fadeOut("slow");
  		
	});
	

	function headerSearch(){
	//	alert("hej");
		var searchString=$(this).val();
		var dataString = "cmd=liveSearch&searchString="+searchString;
	//	alert (dataString);
		$.ajax({
				type: "POST",
				url: "index.php?id=8",
				data: dataString,
				cache: false,
				success: function(html){
					//alert("hej");
				//	alert(html);
			    $("#inpSearchDisplay").fadeIn("slow").html(html);
				//$("#inpSearchDisplay").show();
				//$("#inpSearchDisplay").css("height","100px");
				//$("#inpSearchDisplay").css("width","200px");
				//$("#inpSearchDisplay").html(html);
			//	alert("hejigen");
				}
		});
		return false	
	}
	
	/******************************************
	* Show product selected from livesearch.
	*******************************************	*/
	$("p.liveSearchList").live("click", showLSproduct);
	
	function showLSproduct(){
		var productID=$(this).attr("ID");
		
		window.location.href = "index.php?id=7&product_ID="+productID;
		
		/*$.ajax({
					type: "POST",
					url: "index.php?id=8",
					data: productID,
					cache: false,
					success: function(html){
					    $("#inpSearchDisplay").fadeIn("slow").html(html);
					}
		});
		return false*/
	
	}

	/******************************************
	* Pagination
	*******************************************	*/	
	
	function loadData(dataString){
			$.ajax({
			type: "POST",
			url: "index.php?id=9",
			data: dataString,
			success: function(msg){
				$("#content").ajaxComplete(function(event, request, settings){
					$("#content").html(msg);
					
				});
			}
		});
	}
	$('.pagination li.active').live('click',function(){
		                    
		var page = $(this).attr('p');
		var howToSearch=$('#selSortOrder option:selected').val();
		var whatToSearch=$('#selSortOrder').attr("class");
		var typeToSearch=$("#selSortOrder").attr("rel");
	 
		var dataString="page="+page+"&sortOption="+howToSearch+"&whatToSearch="+whatToSearch+"&typeToSearch="+typeToSearch+"&subSort=null";
		//alert (dataString);
		//$(".data").hide().html("");
		loadData(dataString);
		//$(".data").show();
		
	}); 
	

 
	
	/******************************************
	* Frequently Asked Questions
	*******************************************	*/
	$("#about #sidePanel h4").live("click", showFaqText);
	$("#about #sidePanel p").hide();
	$("#about #sidePanel p:first-child").show();
  $("#about #sidePanel h4").mouseenter(function(){
   	if ($(this).hasClass("active")){
			return false;  
		}else {
  	$(this).css("background-color","#f9f9f9");}
  	}).mouseleave(function(){
  	
  	if ($(this).hasClass("active")){
	return false;  	
  }else {$(this).css("background-color","#f0f0f0");}
  });
  
 	function showFaqText(){
 		$("#about #sidePanel p").hide()
 		$("#about #sidePanel h4").css("background-color","#f0f0f0");
			
 			$(this).css("background-color","#fff100").addClass("active");
 			
 			$(this).next().show();	
		
	};

	/******************************************
	* Request More information form Validation
	*******************************************	*/
$("#reqMoreInfo").live("click",function(){
	$(".prodReqMoreInfo").fadeIn(500);
});

$("#reqInfo").live("click",function(){
	
	$(".prodReqMoreInfo").validate({
	
		rules: {
			email: {
				required: true,
				minlength: 5,
				email: true
			},
			text: {
				required: true,
				minlength: 20
			}
		},
		messages: {
			email: {
				required: "You must enter this field",
				minlength: "Min 5 chars"
			},
			text: {
				required: "You must enter this field",
				minlength: "Enter more than 20 chars"
				
			}
		}
	});
	
});

/***************************************************************
Facebook Replace <b>Quality Rental</b> With their image instead
****************************************************************/
//$("#facebook .fbStatus").
//var el = $('#facebook');
//el.html(el.html().replace(/Quality Rental/ig, "<img class='miniLogo' src='images/minilogo.png' />"));

 
 });

