//<![CDATA[
$(document).ready(function() {
    $("#message_x").click(function() {
        $("#message").slideUp();
        $.get("_ajax_close_message.php", {page: "index.php"});
    });
    $("#email_share_button").click(function() {
        if ($("#email_share_box").is(":hidden")) {
            $("#emailtofriend").show(0);
            $("#email_share_box").slideDown("fast");
        } else {
            $("#email_share_box").slideUp("fast");
            $("#emailconf").hide(0);
        }
    });
    $("#email_share_x").click(function() {
        $("#email_share_box").slideUp("fast");
        $("#emailconf").hide(0);
    });
    $("input[name='cancelaction']:nth(0)").click(function() {
        $("#cancelreason").slideUp("fast");
    });
    $("input[name='cancelaction']:nth(1)").click(function() {
        $("#cancelreason").slideDown("fast");
    });
});

function fnClearDefault(field) {
	if (field.value == field.defaultValue) field.value = "";
}

function fnRestoreDefault(field) {
	if (field.value == "") field.value = field.defaultValue;
}

function fnPass2Text(field) {
	if (field.value == "") {
		field.style.display = "none";
		var inp2 = field.parentNode.getElementsByTagName("input")[0];
		inp2.style.display = "block";
	}
}

function fnText2Pass(field) {
	field.style.display = "none";
	var inp2 = field.parentNode.getElementsByTagName("input")[1];
	inp2.style.display = "block";
	inp2.focus();
}

function fnOpenPopupMessage(id) {
    document.getElementById("iduservideoaction").value = id;
    document.getElementById("overlay").style.visibility = "visible";
    self.scrollTo(0, 0);
    document.getElementById("popup_m500").style.display = "block";
}

function fnClosePopupMessage() {
    document.getElementById("popup_m500").style.display = "none";
    document.getElementById("overlay").style.visibility = "hidden";
}

function fnEmailToFriend() {
        var email = $("input[name='emailaddress']").val();
        var from = $("input[name='fromaddress']").val();
        var idvideo = $("input[name='emailurl']").val();
        var regex = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,})$/;
        if (email.search(regex) == -1) {
            alert("Please enter a valid email address.");
            $("#emailaddress").focus();
            return;
        }
        if (from && from.search(regex) == -1) {
            alert("Please enter a valid from address.");
            $("#fromaddress").focus();
            return;
        }
        $.get("_ajax_email_to_friend.php",{e:email,f:from,u:idvideo});
	$("#emailtofriend").hide(0);
	$("input[name='emailaddress']").val("");
	$("input[name='fromaddress']").val("");
	$("#emailconf").show(0);
}

// VIDEO FUNCTIONS BEGIN

function fnCalculateTimeWatched(userID,videoID,duration) {
    if ($f() && $f().getState() == 3) $.get("_ajax_video_tracker.php",{u:userID,v:videoID,d:duration});
}

function fnCalculateTimeWatchedFreeVideo(videoID) {
    if ($f() && $f().getState() == 3) $.get("_ajax_free_video_tracker.php",{v:videoID});
}

function fnPosesPopupOn(id) {
    document.getElementById("overlay").style.visibility = "visible";
    self.scrollTo(0, 0);
    document.getElementById("poses_video_title").innerHTML = objVideoData[id][0];
    var file = "/videos/" + objVideoData[id][1];
    $f("poses_video_screen", {src:"flowplayer/flowplayer.commercial-3.1.0.swf",wmode:"opaque"}, {
        key: "#$bdde026021ea801163b",
        canvas: {backgroundColor: "#bfbfbf"},
        clip: {scaling: 'fit'},
        plugins: {
            controls: {
                timeColor: '#ffffff',
                backgroundColor: '#252322',
                sliderColor: '#bfbfbf',
                buttonOverColor: '#728B94',
                progressColor: '#e0e0e0',
                durationColor: '#ffffff',
                borderRadius: '0px',
                bufferGradient: 'none',
                bufferColor: '#787878',
                buttonColor: '#ef5a39',
                sliderGradient: 'none',
                progressGradient: 'medium',
                backgroundGradient: [0.6,0.3,0,0,0],
                opacity: 1.0,
                time: false,
                autoHide: 'always'
            }
        }
    }).play(file);
    document.getElementById("poses_video").style.display = "block";
}

function fnPosesPopupOff() {
    document.getElementById("poses_video").style.display = "none";
    document.getElementById("overlay").style.visibility = "hidden";
    $f().stop();
    $f().stopBuffering();
    $f().unload();
    $f() = null;
}

function fnSongClick(URL) {
    $f().stop();
    $f().stopBuffering();
    window.open(URL);
}

// VIDEO FUNCTIONS END

function fnGenerateCommitmentPic(div,idusers) {
   // $("#"+div).slideUp("slow"); 
    $.ajax({ 
    method: "get",url: "_ajax_get_commitmentpic.php",data: "d="+div+"&f="+idusers, 
    //beforeSend: function(){$("#"+div).show("fast");}, 
    success: function(html){ //so, if data is retrieved, store it in html 
    //$("#"+div).show("slow"); //animation 
    $("#"+div).html(html); //show the html inside div 

  }
  }); //close $.ajax( 
 
}

function fnGenerateProfilePic(div,idusers){
   // $("#"+div).slideUp("slow"); 
    $.ajax({ 
    method: "get",url: "_ajax_get_fbprofilepic.php",data: "d="+div+"&f="+idusers, 
    //beforeSend: function(){$("#"+div).show("fast");}, 
    success: function(html){ //so, if data is retrieved, store it in html 
   // $("#"+div).show("slow"); //animation 
    $("#"+div).html(html); //show the html inside  div 
  }
  }); //close $.ajax( 
 
}

function changeGoToRegistration(){
var goto;
goto = document.mydb_addRecord.goto.value = 'paynow.php';
//alert(goto);
}

function addDiscussion(video){
  var discussion = $("#discussion").val();
  if(discussion != ""){
    $.ajax({ 
    method: "get",url: "_ajax_save_discussion.php",data: "v="+video+"&d="+escape(discussion), 
        success: function(html){ //so, if data is retrieved, store it in html 
         $("#video_discuss").show("slow"); //animation 
        $("#video_discuss").html(html); //show the html inside  div 
       }
    });
  }
}

function getMoreComment(video,startpointer){
    $.ajax({ 
    method: "get",url: "_ajax_get_more_discussion.php",data: "v="+video+"&s="+startpointer, 
        success: function(html){ //so, if data is retrieved, store it in html 
         $("#video_discuss_item_more_"+startpointer).show("slow"); //animation 
        $("#video_discuss_item_more_"+startpointer).html(html); //show the html inside  div 
       }
    });
}

function showHideSearchOpt(){
  $("#search_opt").slideToggle("slow");
}

//]]>

