/*PROMODE
if (document.location.protocol != "https:")
{
	var dlabel=getUrlVars()["dlabel"];
	var loc="https://tsx.tracesystems.com" + document.location.pathname+'?dlabel='+dlabel;
	document.location.href = loc;
};
*/



function showVideo(){

	$.ajax({

		   async: true,

		   type: "POST",

		   url: "showvideo.php",

		   data: "opc=showVideo",

		   success: function(data){

			  MySimpleLightBox.loadHTML(data);

		   }

	});

}
	
function getUrlVars() {
	var vars = {};
	var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
		vars[key] = value;
	});
	return vars;
}

function cycleImg(){
	var bgc = $("#splash").attr("class");
	//alert(bgc);
	if(typeof bgc != 'undefined'){
		for(i=1;i<7;i++){
			(bgc.replace('splash','')==i)?$("#splash").removeClass("splash"+i).addClass("splash"+(i+1)):(bgc.replace('splash','')==7)?$("#splash").removeClass("splash7").addClass("splash1"):"";
		}
	}
}
window.setInterval	('cycleImg()',6000);

function processUploadButton(id){
	//alert("ID:"+id);
	 var button = $("#upload_button_"+id);
	 var doclabelval = $("#doclabel_"+id).val();
	 if(typeof doclabelval != 'undefined'){
		 upload = new AjaxUpload('#upload_button_'+id, {
		  action: 'upload.php',
		  name: 'userfile',  data: {
		  },
		  autoSubmit: true,
		  responseType: false,
		  onChange: function(file, extension){
		  	this.setData({'doclabel' : $("#doclabel_"+id).val(),'datatype1' :$("#docuploaderassociatedtype").val(), 'data1' : id});
		  	doclabelval = $("#doclabel_"+id).val();
		  },
		  onSubmit: function(file, extension) {		
					button.text('Uploading');
					this.disable();
					interval = window.setInterval(function(){
						var text = button.text();
						if (text.length < 13){
							button.text(text + '.');					
						} else {
							button.text('Uploading');				
						}
					}, 200);
		  },  onComplete: function(file, response) {
		  			button.text('Upload');
					$("#doclabel_"+id).val("");
					window.clearInterval(interval);
					this.enable();
					var str1='<a href="uploads/'+file+'">'+doclabelval+"</a>";
					$('<li></li>').appendTo('#doclist_'+id).append(str1);
					$(".files").load("load_files.php");
			}
		});

	}
}

$(document).ready(function() {
	$("#text_search").click(function(){
		$(this).val("");
	});
	$("#is_notifiable").click(function(){
		var uid=$("#user_id").val();
		var stat=($(this).attr("checked"))?"1":"0";
		$("#updatemessage").load("do.php?act=is_notifiable&state="+stat+"&uid="+uid);
	});

	$("#is_in_phonebook").click(function(){
		var uid=$("#user_id").val();
		var stat=($(this).attr("checked"))?"1":"0";
		$("#updatemessage").load("do.php?act=is_in_phonebook&state="+stat+"&uid="+uid);
	});

	$(".viewcheckbox").click(function(){
		var id_arr=$(this).attr("id").replace("view_","");
		id_arr=id_arr.split("|");
		var id=id_arr[0];
		var uid=id_arr[1];
		var stat=($(this).attr("checked"))?"1":"0";
		$("#updatemessage").load("do.php?act=viewpermission&id="+id+"&state="+stat+"&uid="+uid);
	});
	$(".notifycheckbox").click(function(){
		var id_arr=$(this).attr("id").replace("notify_","");
		id_arr=id_arr.split("|");
		var id=id_arr[0];
		var uid=id_arr[1];
		var stat=($(this).attr("checked"))?"1":"0";
		$("#updatemessage").load("do.php?act=notify&id="+id+"&state="+stat+"&uid="+uid);
	});
	$(".uploadcheckbox").click(function(){
		var id_arr=$(this).attr("id").replace("upload_","");
		id_arr=id_arr.split("|");
		var id=id_arr[0];
		var uid=id_arr[1];
		var stat=($(this).attr("checked"))?"1":"0";
		$("#updatemessage").load("do.php?act=ulp&id="+id+"&state="+stat+"&uid="+uid);
	});
 	$(".uploadbutton").click(function() {
 		var idval = $(this).attr("id");
 		var id = idval.replace("upload_button_","");
 		processUploadButton(id);
 	});
	$("#upload_button").click(function(){
		$(".files").load("load_files.php");
	});
	$(".liblink").click(function(){	
		var lnk = $(this).attr("href");
		//alert(lnk);
        window.open(lnk);
        return false;
    });
//upload.setData({'datatype1' : $("#doclabel").val(),'data1' :'mel', 'datatype2' : $("#datatype2").val(),'data2' : $("#data2").val()});
   $("#mse+").mouseover(function () {
      $("#mse+").css("background-color","#aaa");
    });
   $("#mse+").mouseout(function () {
      $("#mse+").css("background-color","#fff");
    });
    
 	$("#taboverx").mouseover(function(){
 		("#taboverx").css("background-color","black");
 		alert("ya");
 	});

 	$(".upload").click(function(){
 		
 	});
 	$(".confirmdelete").click(function(){
		var answer = confirm("Are you sure you want to delete??")
		if (answer){
			this.form.submit();
		}
		else{
			return false;
		}
 	});
	
 	$('.image_item').hover(
	 	function(){;
	 		$("#pinfoimg").attr('src',this.id);
	 	},
	 	function(){
	 		$("#pinfoimg").attr('src','');
	 	}
 	);
 	$("select.active_input").change(function(){
    	//this.submit();
	});
 	$("#placetogo").change(function(){
   		var selected = $("#placetogo option:selected");
	    if(selected.val() != 0){  
	       //document.location=selected.val();  
	    } 
	});
 	$(".confirmdelete").click(function(){
		var answer = confirm("Are you sure you want to delete??")
		if (answer){
			this.form.submit();
		}
		else{
			return false;
		}
 	});
	/*

 	$(":checkbox").click(function(){
    	$.ajax({
		   type: "GET",
		   url: "update.php",
		   data: "table=category&fieldname=is_visible&id="+$(this).attr("value")+"&val="+$(this).is(":checked"),
		   dataType: 'html', 
		   success: function(x){
		     //alert( "Data Saved: " + x );
		   }
		 });
	});
	//$(".side_navigation li li > *").hide();	$(".side_navigation li + li > a,#navbar a").click(function(){
		var href_array= $(this).attr('href').split("/");
		var part_num = 0;
		while (part_num < href_array.length) {
			lastPart = href_array[part_num];
			 part_num += 1;
		}
		var str=lastPart.replace(/#/,"");
		//var str=lastPart;
		//$("sub_"+str).load("data.php?id="+str); 
		$("#sub_"+str).load("data.php?id="+str);
		//$("#content").load("catalog.php?category_id="+str);
    });
    */
    $('#billingcopy:checkbox').click(function(){
		$("input[@name='billing_first_name']").val($("input[@name='first_name']").val());
		$("input[@name='billing_last_name']").val($("input[@name='last_name']").val());
		$("input[@name='billing_city']").val($("input[@name='city']").val());
		$("input[@name='billing_state']").val($("input[@name='state']").val());
		$("input[@name='billing_zip']").val($("input[@name='zip']").val());
		$("input[@name='billing_phone']").val($("input[@name='phone']").val());
		$("input[@name='billing_country']").val($("input[@name='country']").val());
		$("input[@name='billing_address']").val($("input[@name='address']").val());
		$("input[@name='billing_address_2']").val($("input[@name='address_2']").val());
		$("input[@name='billing_company']").val($("input[@name='company']").val());
	 });
    $('.links').click( function() {
        $('.stuff').load('do.php?act='+this.value);
    });
 /*  
    $('#form1').submit( function() {
        $('#elm1').load('do.php?act='+$('#elm1').val);
        $('#main_profile_content').val("ya");
        //alert("yo");
    });
  */
    $(".sql").click( function() {
     	if(this.checked){
     		x=1
     	}else{
     		x=0
     	}
        $('.sql').load('do.php?id='+this.id+'&value='+x);
    });
    
    $(".upload").click( function() {
        $('.thumb').load('image.php?product_id='+this.id);
    });    
    $(".image_item").click(function() {
		var changeSrc = $(this).attr("href");
		$("#image_main").attr("src",changeSrc);
	});

     $(".sql_delete").click( function() {
        $('.sql').load('do.php?id='+this.id);
    });     
  $('.bubbleInfo').each(function () {
    // options
    var distance = 10;
    var time = 250;
    var hideDelay = 500;

    var hideDelayTimer = null;

    // tracker
    var beingShown = false;
    var shown = false;
    
    var trigger = $('.trigger', this);
    var popup = $('.popup', this).css('opacity', 0);
    $([trigger.get(0), popup.get(0)]).mouseover(function () {
      // stops the hide event if we move from the trigger to the popup element
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

      // don't trigger the animation again if we're being shown, or already visible
      if (beingShown || shown) {
        return;
      } else {
        beingShown = true;

        // reset position of popup box
        popup.css({
          top: -100,
          left: -33,
          display: 'block' // brings the popup back in to view
        })

        // (we're using chaining on the popup) now animate it's opacity and position
        .animate({
          top: '-=' + distance + 'px',
          opacity: 1
        }, time, 'swing', function() {
          // once the animation is complete, set the tracker variables
          beingShown = false;
          shown = true;
        });
      }
    }).mouseout(function () {
      // reset the timer if we get fired again - avoids double animations
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      // store the timer so that it can be cleared in the mouseover if required
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
          // once the animate is complete, set the tracker variables
          shown = false;
          // hide the popup entirely after the effect (opacity alone doesn't do the job)
          popup.css('display', 'none');
        });
      }, hideDelay);
    });
  });
  	//cycleImg();
	/*
	$('#fileupload').fileupload({
    drop: function (e, data) {
        $.each(data.files, function (index, file) {
            alert('Dropped file: ' + file.name);
        });
    },
    change: function (e, data) {
        $.each(data.files, function (index, file) {
            alert('Selected file: ' + file.name);
	        });
	    }
	});
	*/
	
	$("#demo a").click(function(){
		var lnk = $(this).attr("href");
	});
					   
	$(".toggle-container").hide();
		$("h2.toggler").toggle(function(){
			$(this).addClass("toggler-active"); 
			}, function () {
			$(this).removeClass("toggler-active");
		});	
		$("h2.toggler").click(function(){
			$(this).next(".toggle-container").slideToggle("slow,");
		});
		$('h2.h2-open-onload').addClass("toggler-active"); 
		$('.open-onload').show(); 
		$("h2.h2-open-onload").toggle(function(){
			$(this).removeClass("toggler-active"); 
			}, function () {
			$(this).addClass("toggler-active");
		});
	
	
	// Remove bottom border from last item
		$('.home-products-list .product-short:last-child').css("border", "none");
	
	// Homepage tabs
		$("#tabs").tabs();
	/*
	// Homepage cycle
		$('#home-slides').cycle({ 
	    timeout:  10000 
	});
	*/
	$(".AddContentButton").click(function(){
		var id=$(this).attr("id").replace("AddContentButton-","");
		var idpath=id;
		var sel = $("#AddContentSelector-"+idpath).val();
		var secid="#tabbedsection-"+idpath;
		var main_id=id.split('-')[1];
		//alert(main_id);
		switch(sel){
			case "library":{
				$(secid).append("<div id='createLibrary-"+main_id+"'></div>");
				$("#createLibrary-"+main_id).load("do.php?act=create&type=document&id="+main_id);
			}break;
			case "content":{
				$(secid).append("<div id='createContent-"+main_id+"'></div>");
				$("#createContent-"+main_id).load("do.php?act=create&type=content&id="+main_id);
			}break;
		}
	});
	$("#nav li:last").css("border-right","none");
	$("#nav li:first").css("border-left","none");
	$(".footer-links li:last").css("border-right","none");
	$("[id^='tabbedsection-']").tabs();	$(".sidebutton a").click(function(){
		var id = $(this).attr("href");
		$("div:visible[id^='section-']").hide();
		//$(".tabbedsection").css("background-color","#aaa");
		$(".sidebutton li").css("background-color","#ddd");
		$(this).parents('li:first').css("background-color","#fff");
		$("#"+id).show();
		return false;
	});
	$(".bk").click(function(){
		history.go(-1);
	});
	$(".newwindow").click(function(){
		var nw = $(this).attr("href");
        window.open(nw);
        return false;
 	});
 	
 	/*
if($("#upload_button").length){
 		$("#upload_button").live('click', function() {
		$(".files").load("load_files.php");
	});
	$(".liblink").click(function(){	
		var lnk = $(this).attr("href");
		//alert(lnk);
        window.open(lnk);
        return false;
    });
}
*/
 });
 

$(function()
	{
		//
		
	}
);
