// JavaScript Document
// Custom Script for Venturi Tools, LLC. All Rights Reserved
// Programming by Michael Willis @ butlerworldwide.com
var swfu, swfu2, toggled;

 function onSelectChange(){  
     var selected = $("#category option:selected");       
     var output = "";  
     if(selected.val() != 0){  
         $("#div_subCat").show();  
    }  
 } 

//-------------------------------------------------------------------//
//	[urlParam insert by Mathias Bank (http://www.mathias-bank.de)]   //
//-------------------------------------------------------------------//

jQuery.fn.extend({

 getUrlParam: function(strParamName){
	  strParamName = escape(unescape(strParamName));
	  
	  var returnVal = new Array();
	  var qString = null;
	  
	  if ($(this).attr("nodeName")=="#document") {
	  	//document-handler
		
		if (window.location.search.search(strParamName) > -1 ){
			
			qString = window.location.search.substr(1,window.location.search.length).split("&");
		}
			
	  } else if ($(this).attr("src")!="undefined") {
	  	
	  	var strHref = $(this).attr("src")
	  	if ( strHref.indexOf("?") > -1 ){
	    	var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	  		qString = strQueryString.split("&");
	  	}
	  } else if ($(this).attr("href")!="undefined") {
	  	
	  	var strHref = $(this).attr("href")
	  	if ( strHref.indexOf("?") > -1 ){
	    	var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	  		qString = strQueryString.split("&");
	  	}
	  } else {
	  	return null;
	  }
	  	
	  if (qString==null) return null;
	  
	  
	  for (var i=0;i<qString.length; i++){
			if (escape(unescape(qString[i].split("=")[0])) == strParamName){
				returnVal.push(qString[i].split("=")[1]);
			}
	  }
	  
	  if (returnVal.length==0) return null;
	  else if (returnVal.length==1) return returnVal[0];
	  else return returnVal;
	}
});

$(document).ready(function(){

//--------------------------------------------------//
//	[custom function to Initiate the FCK Editor]    //
//--------------------------------------------------//
$(function(){
 $.fck.config = {
  path: './lib/fckeditor/',
  height: '440'
 };
 $('textarea.fck').fck();
});

$("#div_subCat").hide();

//------------------------------------------------------------------------//
//	[custom function to create rounded corners w/o images: DO NOT EDIT]   //
//------------------------------------------------------------------------//
      settings = {
          tl: { radius: 8 },
          tr: { radius: 8 },
          bl: { radius: 8 },
          br: { radius: 8 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      }
	  settings2 = {
          tl: { radius: 8 },
          tr: { radius: 8 },
          bl: { radius: 0 },
          br: { radius: 0 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      }
	  settings3 = {
          tl: { radius: 8 },
          tr: { radius: 8 },
          bl: { radius: 8 },
          br: { radius: 8 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      }
      var myBoxObject = new curvyCorners(settings, "page");
      myBoxObject.applyCornersToAll();
	  
	  var myBoxObject2 = new curvyCorners(settings2, "tab");
      myBoxObject2.applyCornersToAll();
	  
	  var myBoxObject3 = new curvyCorners(settings3, "custom");
      myBoxObject3.applyCornersToAll();


//------------------------------------------------------//
//  		[Hide Featured Products @ admin] 		    //
//------------------------------------------------------//	

		if ($(document).getUrlParam("act")=="admin") {
		  	$("#featured").hide();
			toggled = true;
			$("#tab_toggle").html("+ Show");
		}

//------------------------------------------------------//
//   [Venturi Inc Horizontal Slide Featured Products]   //
//------------------------------------------------------//	
	var center = 1;
	var max = 3;

	$("#mover1").animate({ left: "0px"}, { duration: 1} );
	$("#mover2").animate({ left: "850px"}, { duration: 1} );
	$("#mover3").animate({ left: "-850px"}, { duration: 1} );

	$("#featured_ra").click(function(){	
		center++;
		
		if (center == max) { right = 1; left=max-1;}
		else if (center > max) { left= max; center=1; right = 2;}
		else {right = center+1;left= center-1;}
		
		$("#mover"+left).animate({ left: "-850px"}, { duration: 800} );
		$("#mover"+center).animate({ left: "0px"}, { duration: 800} );
		$("#mover"+right).animate({ left: "850px"}, { duration: 1} );		
	});
	
	$("#featured_la").click(function(){	
		center--;
	
		if (center == 1) { left = max; right = 2;}
		else if (center < 1) { left= max-1; center=max; right = 1;}
		else {right = center+1;left= center-1;}
	    
		$("#mover"+center).animate({ left: "0px"}, {duration:800} );
		$("#mover"+right).animate({ left: "850px"}, { duration: 800} );
		$("#mover"+left).animate({ left: "-850px"}, { duration: 1} );		
	});

//-------------------------------------------------//
// [Venturi Inc Featured Products Toggle On/Off]   //
//-------------------------------------------------//					   
var toggled1=false;
var toggled2=false;
//$("#header_hints").slideToggle(1); ---Descided not to use.

$("#tab_toggle").click(function () {
	if(toggled==false){
	  $("#tab_toggle").html("+ Show");
	  $("#featured").slideToggle("slow");
	  toggled = true;
	}
	else{
	  $("#tab_toggle").html("- Hide");
	  $("#featured").slideToggle("slow");
	  toggled = false;
	}
});

$("#tab1").click(function () {
	if(toggled1==false){
	  $(this).children("strong").text("+ Show");
	  $(this).parent(".divtoggle").children(".custom").children(".stylized").slideToggle("fast");
	  toggled1 = true;
	}
	else{
	  $(this).children("strong").text("- Hide");
	  $(this).parent(".divtoggle").children(".custom").children(".stylized").slideToggle("fast");
	  toggled1 = false;
	}
});

$("#tab2").click(function () {
	if(toggled2==false){
	  $(this).children("strong").text("+ Show");
	  $(this).parent(".divtoggle").children(".custom").children(".stylized").slideToggle("fast");
	  toggled2 = true;
	}
	else{
	  $(this).children("strong").text("- Hide");
	  $(this).parent(".divtoggle").children(".custom").children(".stylized").slideToggle("fast");
	  toggled2 = false;
	}
});

//---------------------------//
//    	[Loading AJAX]	     //
//---------------------------//
$('.loader').click(function () {
	$('#loader').html('<div id="loading" style="width: 70px; height: 40px; display: inline-block;" />');
	var tabtitle = $(this).attr("value");
	$.ajax({
	  beforeSend: function(){ act=$(this).attr("id");},
	  url: "pages/admin/"+$(this).attr("id")+".php",
	  cache: false,
	  success: function(html){
		  $("#admin_container").slideToggle("slow", function() {
		  $("#admin_container").empty().html(html);
		  //$('#title_tab').html(tabtitle);
		  $("#title_tab").fadeOut("fast", function(){$("#title_tab").empty().html(tabtitle).fadeIn('slow')});
		  	}).slideToggle("slow", function(){ $('#loader').slideToggle("slow")});
		      	 
  	   }//end success
	});//end ajax call
});//end loader.click

//---------------------------//
//    	[Forms AJAX]	     //
//---------------------------//
$('#submit').click(function () {
	$('#loader2').html('<div id="loading" style="width: 70px; height: 40px; display: inline-block; margin-top:15px;" />');
	//var dataString = $("input#realname").val();
	var dataString = $("#forms").serialize();
$.ajax({
	  type: "GET",
	  url: "pages/admin/addcat.php?form=submit",
  	  data: {dataString:[dataString]},
	  success: function(html){
		  $("#form_submit").fadeOut("medium", function() {
		  $("#form_submit").empty();
		  $("#form_submit").html(html);
		  		}).fadeIn("medium", function() {$('#loader2').html("")} );
  	   }//end success
	});//end ajax call
});//end loader.click



//---------------------------//
// [Venturi Inc Slideshow ]  //
//---------------------------//
/*
	//Preload Image Function
	jQuery.preloadImages = function()
	{
	  for(var i = 0; i<arguments.length; i++)
	  {
		jQuery("<img>").attr("src", arguments[i]);
	  }
	}

	//init				   
	var cur_num = 0;

	var app_array_text = [ 
	//Applet Array TEXT
	//Each of the following lines contain a page of the html text on the homepage applet. Use H2 tags for title and <p> tags for the paragraph.
	"Product 1",
	"Product 2",
	"Product 3",
	"Product 4",
	"Product 5",
	"Product 6",
	"Product 7",
	"Product 8",
	"Product 9",
	"Product 10"
	 ];
	
	var app_array_img = [
	//Applet Array IMAGES
	//Each of the following lines contain a page of the html images on the homepage applet. Use <img> tags for the image use single quotes (') for the src.
	"images/item_demo.jpg",
	"images/item_demo.jpg",
	"images/item_demo.jpg",
	"images/item_demo.jpg",
	"images/item_demo.jpg",
	"images/item_demo.jpg",
	"images/item_demo.jpg",
	"images/item_demo.jpg",
	"images/item_demo.jpg",
	"images/item_demo.jpg"
	 ];

	$.preloadImages(app_array_img[0],app_array_img[1],app_array_img[2],app_array_img[3],app_array_img[4]);
	
	
	//Data Function to Calculate Text and Images
	function printData()
	{
		$("#featured_item1").fadeOut("fast", function(){$("#featured_item1").empty().html("<img src='"+app_array_img[cur_num]+"'><p>"+app_array_text[cur_num]+"</p>").fadeIn('slow')});
		$("#featured_item2").fadeOut("fast", function(){$("#featured_item2").empty().html("<img src='"+app_array_img[cur_num+1]+"'><p>"+app_array_text[cur_num+1]+"</p>").fadeIn('slow')});
		$("#featured_item3").fadeOut("fast", function(){$("#featured_item3").empty().html("<img src='"+app_array_img[cur_num+2]+"'><p>"+app_array_text[cur_num+2]+"</p>").fadeIn('slow')});
		$("#featured_item4").fadeOut("fast", function(){$("#featured_item4").empty().html("<img src='"+app_array_img[cur_num+3]+"'><p>"+app_array_text[cur_num+3]+"</p>").fadeIn('slow')});
		$("#featured_item5").fadeOut("fast", function(){$("#featured_item5").empty().html("<img src='"+app_array_img[cur_num+4]+"'><p>"+app_array_text[cur_num+4]+"</p>").fadeIn('slow')});
	}
	
	//Load First Data Set
	printData(); //Load Data
	
	//Next Button Function for Timer Call
	function nextButton()
	{
		if(cur_num == app_array_text.length-2){
			printData();
		}
		if (cur_num == app_array_text.length-1){
			cur_num = 0;
			printData();
		}
		else{
			cur_num=cur_num+5;
			printData();
			}
	}
	
	//setInterval(nextButton, 8000);
	
	//Next Button
		$('#featured_ra1').click(function() {							   
			nextButton();
		});
		
	 //Previous Button 
		$('#featured_la2').click(function() {
		
		if(cur_num <= 0){
			printData();
		}
		if (cur_num == 0){
			cur_num = app_array_text.length-1;
			printData();
		}
		else{
			cur_num=cur_num-5;
			printData();
			}
		});
	
*/
	//End	
  $("#category").change(onSelectChange);  
});
