/* Nowvangelist scripts */

$(document).ready(

function(){

// Masking


// Do hovers on input boxes
ohover();

$(".ftr_phonec").click(

	function(){

			window.open("http://www.instinctthephone.com");
	}

)

$(".ftr_phonec").hover(
      function () {
        $('.ftr_phone').show();
      },
      function () {
	    $('.ftr_phone').hide();

      }
    );




$('*[rel*=masked]').defaultvalue();
   $('a[rel*=facebox]').facebox();




//IE6 SPECIFIC
if($.browser.msie && $.browser.version  < 7 ){
     $(function(){
				$('.pfix').pngFix();
				document.execCommand("BackgroundImageCache",false,true);


				})
}

}
)

function initprofileTabs(tabg){

	$(".pt a").each(
				function(){
					$(this).click(
		function(){
			$($(this).parent().get(0)).removeClass("current");
			f_profiletabs($(this).parent().get(0).id, tabg);
		}
		)
	}

	)

}
var currentab="";

function f_profiletabs(tabid, tabg){

var ajaxAction;


switch(tabid){

	case "profileTab-1" :
	$(tabg).css("background-position", "0 0");
	ajaxAction = mytopics_url;

	break;

	case "profileTab-2" :
		$(tabg).css("background-position", "0 -60px");

	ajaxAction = mycomments_url;


	break;


	case "profileTab-3" :
		$(tabg).css("background-position", "0 -120px");

	ajaxAction = mydisc_url;


	break;

	default :
	ajaxAction = mytopics_url;
	break;

}

if(tabid != currentab){



	   $.ajax({
   type: "GET",
   url: ajaxAction,
   data: "",

   beforeSend: function(){
     $.facebox('<div style="top:300px;left:200px;position:absolute"><img src="/includes/images/loading.gif" /></div>');
	 //$('#nc2').html('<img src="/includes/images/loading.gif" />');
   },

   success: function(data){
	   f_hideoverlay();
    if($.browser.msie){

	$(".threads")[0].innerHTML=data;
	}
	else{
		
		$(".threads").html(data);	
	}
	
	toggleTabs(tabid);
   }



 });




			currentab = tabid;

}


}


function toggleTabs(tabid){



$('#profile_nav ul li').each(
	function(){

	if($(this)[0].id == tabid){
	$(this).addClass("current");
	}
	else{
			$(this).removeClass("current");


	}


	}
	)
}



function f_hideoverlay()
{

	jQuery.facebox.close();
	jQuery.facebox.close();


}


function ghtoggle(){

	$("#gethelpnow a").toggle(function()
			{


			$('#chatbtn').slideDown();
			$("#gethelpnow a").css("background-position", "0 -80px");},function(){
					$('#chatbtn').slideUp();
			$("#gethelpnow a").css("background-position", "0 0");

			}
		);


}

function fatoggle(){
	var hpcol = $("#hp_col1").length ;
	if(hpcol == 0)
	{
			$('#fa_i').slideUp();
			$("#fal").css("background-position", "0 -80px");


		$("#fal").toggle(function()
			{


			$('#fa_i').slideDown();
			$("#fal").css("background-position", "0 -80px");},function(){
					$('#fa_i').slideUp();
			$("#fal").css("background-position", "0 0");

			}
		);










	}
}


function initPosting(){

//Hide The error block

$('#comment_area .error').hide();

// Fix IE6 rows issue.
if(document.all && $('#txta_comments').length>0) $('#txta_comments')[0].rows = "7";

//Comment Area Controls
var ca = $('#comment_area_controls');

//Textarea
var ta  =$('#txta_comments');

//Value of the Textarea
var tval = ta.val();

//Preview Button
var pbtn = $(".btn_preview");

//Edit Button
var ebtn = $(".btn_edit");

//Post Button
var postbtn = $("#postcomment");

// Preview Layer
var player = $("#previewContainer");

// Error Div
var ed = $('#comment_area_controls .error');

// Preview layer  P element
var pcontent = $("#previewContent");


pbtn.click(function(){

//Value of the Textarea
var tval = ta.val();
					tstr = jQuery.trim(tval);
					if(tstr.length > 0){
						pcontent.html(tval);
						ca.fadeOut();
						player.fadeIn('slow');
						ebtn.show();
						pbtn.hide();
						ed.html("");
					}
					else{
							ed.fadeIn();
							ed.html("<p>Please enter a comment to preview or post</p>");

						}

					}
		   )

ebtn.click(function(){

			player.fadeOut();
			ca.fadeIn();
			ed.hide();
			pbtn.show();
			ebtn.hide();
			pcontent.html("");


					}
			)

postbtn.click(function(){

			var tval = ta.val();
					tstr = jQuery.trim(tval);
					if(tstr.length > 0){
						$('#frmask').submit();
					}
					else{
							ed.show();
							ed.html("<p>Please enter your comment</p>");
						}
					}
				)
}


/* Editprofile */

function editProfile(){

$('.myProfile').hide();
$('.editmyProfile').show();
}
/* Myprofile */

function myProfile(){

$('.myProfile').show();
$('.editmyProfile').hide();
}
/* Tagging */
function submitTheTag(ajaxAction){

var txt_tags = $('#txt_tagtext')[0].value;
//alert(ajaxAction);
$.get(ajaxAction, { txt_tags: txt_tags },
  function(data){
	$(".threadtagging").html(data);

	});

}

	function initTagMe(ajaxAction){

		$('#txt_tagtext').keyup(
								function(e){
									if(e.keyCode=="13"){

										//Do ajax request here
										//$.get(ajaxAction,
										submitTheTag(ajaxAction);
										$('#tagModule').fadeOut();
									}
								}
								)
		$('#tag_add_btn').click(
								function(){
									//if(e.keyCode=="13"){


										//Do ajax request here
										//$.get(ajaxAction,
										submitTheTag(ajaxAction);
										$('#tagModule').fadeOut();

									//}
								}
								)






$.getScript("/includes/scripts/jqb.js");
		$('#addtopic').click(
				function(e){
						var linkposleft = e.pageX - 100;
						var linkpostop = e.pageY -80;

						var tagModule = $('#tagModule');
						$('#txt_tagtext')[0].value = $('#txt_tagtext').attr("defvalue");
						//tagModule.pngFix();
						//linkpos + linkpos.left+"left");
						//var blOffset = r_bloffset() || 100;


						tagModule.css("left",linkposleft +"px");
						tagModule.css("top",linkpostop+"px");
						tagModule.fadeIn('slow');
						tagModule.focus();
						tagWindowWatcher();
				}

			)
	}


function r_bloffset(){

	var bOs= $.browser.browser()+$.browser.OS()+$.browser.version.string();
	switch (bOs){

		case "FirefoxWin":

		break;

		case "safariMac":


		break;

		case "Internet ExplorerWindows7.0":

		return -15;

		break;

		default:
		break;





	}

}
function tagWindowWatcher(){
		$(window).keyup(
								function(e){
									if(e.keyCode=="27"){

										//Do ajax request here
										//$.get(ajaxAction,
								$('#tagModule').fadeOut();


									}
								}
								)


$('#shell').click(


						 	function(e){
								if(e.target.id !="addtopic"  ){
								if(e.target.id!="tagModule"){
								$('#tagModule').fadeOut();
								}
						}
					}
				)



				unbindtagWindow();


}
function unbindtagWindow(){

				  $('#shell').unbind('click',tagWindowWatcher);

}function signout() {
	jQuery.facebox(function() {
  		 jQuery.get(signouturl, function(data) {
    	 	jQuery.facebox(data);
    	})
	})
}

/* Tagging */
function refreshDivTag(ajax_url, div_tag) {
    $.ajax({
   type: "POST",
   url: ajax_url,
   data: "",

   beforeSend: function(){
     $.facebox('<img src="/includes/images/loading.gif" />');
	 //$('#nc2').html('<img src="/includes/images/loading.gif" />');
   },

   success: function(data){
     $('#nc2').html('');
	 $('#nc2').html(data);
	 jQuery('a[rel*=facebox]').facebox();
   }



 });


}

/* Helper function */

function cascadedstyle(el, cssproperty, csspropertyNS){
	var er= el.style.cssText;
	er=el.style.cssText;
	//alert(er);
if (el.currentStyle) //if IE5+
return el.currentStyle[cssproperty]
else if (window.getComputedStyle){ //if NS6+
var elstyle=window.getComputedStyle(el, "")
return elstyle.getPropertyValue(csspropertyNS)
}
}


/* The Footer */


function dofooter(fpath1,fpath2, xpath){

			var footerflashvars = {};
			footerflashvars.configUrl =xpath;
			var footerparams = {};
			var footerattributes = {};
			footerattributes.id = "footercontentobj";
			footerparams.wmode = "transparent";
			swfobject.embedSWF(fpath1, "footercontent", "1005", "86", "8.0.0", "/includes/scripts/so/expressInstall.swf", footerflashvars, footerparams, footerattributes);
/* Phone */
	var	footerphoneflashvars = {};
			//footerphoneflashvars.testvar = "testvar";
			var footerphoneparams = {};
			var footerphoneattributes = {};
			footerphoneattributes.id = "footerphonecontent";
			footerphoneparams.wmode = "transparent";
			swfobject.embedSWF(fpath2, "footerphone", "115", "127", "8.0.0", "/includes/scripts/so/expressInstall.swf", footerphoneflashvars, footerphoneparams, footerphoneattributes);
/* Phone */

}




      jQuery.fn.replace = function() {

          var stack = [];

          return this.domManip(arguments, true, 1, function(a){

              this.parentNode.replaceChild( a, this );

              stack.push(a);

          }).pushStack( stack );

      };


function domasking(obj){


if(!$.browser.msie){
	obj.type="password";
	obj.value="";
	obj.select();
	}
	else{
	var ip=obj;
	var np=ip.cloneNode(true);
		np.setAttribute('type','password');
		np.type='password';
		np.value='';
		np.onclick ='';
		np.className='';

			//alert('gere');
		try{
		
			$(ip).replace(np);
							np.focus();
							np.focus();


			 
		}
		catch(e){
		
		}
		//obj.unbind('click', domasking)

		
	}

}

function ohover(hoverposx,hoverposy,defposx,defposy){
	var cposx = hoverposx|| "0";
	var cposy = hoverposy|| "-29px";
	var dposx = defposx|| "0";
	var dposy = defposy|| "0";



						  
		
	//Input  hover
	
$('.ohover').hoverIntent(

		function(){				
			$(this).css("background-position",cposx+" "+ cposy);

		},
		function(){
			$(this).css("background-position",dposx+" "+ dposy);

		}

)

	
}


