var sState = null;
var sVidTitle = null;
var nPriSort = null;
var nStart = null;
var nVidCat = null;
var nVidID = null;
var nVidSec = null;


// Functions >>>>
var Add_Bookmark = function(vidid, vidtitle, vidsec ) {
	$j.ajax({
		type: "GET",
		url: "/includes/Site/vidtemp_remote_bookmark.php",
		data: "vidid=" + vidid + "&vidtitle=" + vidtitle + "&vidsec=" + vidsec,
		success: Handle_Bookmark_Resp
	});
}

var Get_VidList = function(vidid, vidcat, prisort, vidsec, limit, page) {
	$j.ajax({
		type: "GET",
		url: "/includes/Site/vidtemp_remote_vidlist.php",
		data: "vidid=" + vidid + "&vidcat=" + vidcat + "&prisort=" + prisort + "&vidsec=" + vidsec + "&limit=" + limit + "&page=" + page,
		success: Handle_VidList_Resp
	});
}

var Handle_Bookmark_Resp = function(resp) {
	if(resp == "/My/") {
		window.location = "/My/";
	} else {
		$j("#vidTempBookmark").html('<a id="vidTempBookmarkedLink" href="/My/">This page has been bookmarked</a>');
	}
}

var Handle_Email_Resp = function(resp) {
        if(resp == 'success') {
                Reset_Email_Form();
                $j("#emailResponse").html("Success! Your e-mail has been sent.");
        } else {
                var aErrors = resp.split("\n");
                var sErrors = aErrors.join("<br />");
                $j("#emailResponse").html("Errors:<br />" + sErrors);
        }
}

var Handle_VidList_Resp = function(resp) {
	$j("#vidListBody").html(resp);

	$j("#nextBtn").click(function() {
		nStart = ($j("input[@name=vidListPage]").val()) ? Number($j("input[@name=vidListPage]").val()): 0;
		Get_VidList(nVidID, nVidCat, nPriSort, nVidSec, 4, (++nPage));
	});
	
	$j("#prevBtn").click(function() {
		nStart = ($j("input[@name=vidListPage]").val()) ? Number($j("input[@name=vidListPage]").val()): 0;
		Get_VidList(nVidID, nVidCat, nPriSort, nVidSec, 4, (--nPage));
	});
}

var Reset_Email_Form = function() {
	$j("#emailResponse").html("");
	$j("#emailForm")[0].reset();
}

var Init_VB_VidTemp_Scripts = function() {

	nPriSort = $j("input[@name=currVidType]").val();
        nVidCat = $j("input[@name=currVidCat]").val();
        nVidID = $j("input[@name=currVidID]").val();
        nVidSec = $j("input[@name=currVidSec]").val();
	sVidTitle = $j("input[@name=currVidTitle]").val();

        $j("#vidFullDesc").hide();

        // Bookmark Control >>>
        $j("#vidTempBookmarkLink").click(function() {
                Add_Bookmark(nVidID, sVidTitle, nVidSec);
        });


        // EMail Dropdown >>>
	$j("input[@name=cancel]").unbind('click');
        $j("input[@name=cancel]").bind("click", function() {
                Reset_Email_Form();
                $j("#vidTempEmail").animate({height: 'toggle', opacity: 'toggle'}, "normal");
        });

        $j("input[@name=submit]").click(function() {
                var sComments = $j("textarea[@name=additionalComments]").val();
                var sFrom = $j("input[@name=fromEmailAddress]").val();
                var sTitle = $j("input[@name=currVidTitle]").val();
                var sTo = $j("input[@name=toEmailAddress]").val();
                var sUrl = $j("input[@name=currVidUrl]").val();
                var nVidID = $j("input[@name=currVidID]").val();
                var nVidSec = $j("input[@name=currVidSec]").val();

                //alert("to="+sTo+"&from="+sFrom+"&comments="+sComments+"&id="+nVidID+"&section="+nVidSec+"&title="+sTitle+"&url="+sUrl);
                $j.ajax({
                        type: "POST",
                        url: "/includes/Site/vidtemp_remote_email.php",
                        data: "to="+sTo+"&from="+sFrom+"&comments="+sComments+"&id="+nVidID+"&section="+nVidSec+"&title="+sTitle+"&url="+sUrl,
                        success: Handle_Email_Resp
                });
        });

        $j("#emailTop a").unbind("click");
        $j("#emailTop a").bind("click", function() {
                Reset_Email_Form();
                $j("#vidTempEmail").animate({height: 'toggle', opacity: 'toggle'}, "normal");
        });


	$j("#vidTempEmailLink").unbind("click");
	$j("#vidTempEmailLink").bind("click", function() {
                Reset_Email_Form();
                $j("#vidTempEmail").animate({height: 'toggle', opacity: 'toggle'}, "normal");
	});

	
        // EMail Dropdown Positioning >>>
        var oEmail = $j("#vidTempEmail");
        var oEmailOff = $j("div#vidOptions").offset();
        var nOffsetTop = oEmailOff.top + 15;
        var nOffsetLeft = 610;
        oEmail.css("top", nOffsetTop);
        oEmail.css("left", nOffsetLeft);

	$j("#vidSmallDesc p a").unbind("click");
	$j("#vidSmallDesc p a").bind("click", function() {
                $j("#vidSmallDesc").animate({height: 'toggle'}, "normal");
                $j("#vidFullDesc").animate({height: 'toggle'}, "normal").css("display", "block");
        });

	$j("#vidFullDesc p a").unbind("click");
        $j("#vidFullDesc p a").bind("click", function() {
                $j("#vidSmallDesc").animate({height: 'toggle'}, "normal");
                $j("#vidFullDesc").animate({height: 'toggle'}, "normal").css("display", "block");
        });

}

var VidTemp_Reinit = function() {

        nPriSort = $j("input[@name=currVidType]").val();
        nVidCat = $j("input[@name=currVidCat]").val();
        nVidID = $j("input[@name=currVidID]").val();
        nVidSec = $j("input[@name=currVidSec]").val();
        sVidTitle = $j("input[@name=currVidTitle]").val();

        var oEmail = $j("#vidTempEmail");
        var oEmailOff = $j("div#vidOptions").offset();
        var nOffsetTop = oEmailOff.top + 15;
        var nOffsetLeft = 610;
        oEmail.css("top", nOffsetTop);
        oEmail.css("left", nOffsetLeft);

        // Description Dropdown >>>
        $j("#vidFullDesc").hide();

        $j("#vidSmallDesc p a").unbind("click");
        $j("#vidSmallDesc p a").bind("click", function() {
                $j("#vidSmallDesc").animate({height: 'toggle'}, "normal");
                $j("#vidFullDesc").animate({height: 'toggle'}, "normal").css("display", "block");
        });

        $j("#vidFullDesc p a").unbind("click");
        $j("#vidFullDesc p a").bind("click", function() {
                $j("#vidSmallDesc").animate({height: 'toggle'}, "normal");
                $j("#vidFullDesc").animate({height: 'toggle'}, "normal").css("display", "block");
        });

/*        // Video List Controls >>>
        $j("#nextBtn").click(function() {
                nPage = ($j("input[@name=vidListPage]").val()) ? Number($j("input[@name=vidListPage]").val()): 0;
                Get_VidList(nVidID, nVidCat, nPriSort, nVidSec, 4, (++nPage));
        });


        $j("#prevBtn").click(function() {
                nPage = ($j("input[@name=vidListPage]").val()) ? Number($j("input[@name=vidListPage]").val()): 0;
                Get_VidList(nVidID, nVidCat, nPriSort, nVidSec, 4, (--nPage));
        });*/

}

var VidTemp_Reinit_VidList = function() {
        // Video List Controls >>>
        $j("#nextBtn").click(function() {
                nPage = ($j("input[@name=vidListPage]").val()) ? Number($j("input[@name=vidListPage]").val()): 0;
                Get_VidList(nVidID, nVidCat, nPriSort, nVidSec, 4, (++nPage));
        });


        $j("#prevBtn").click(function() {
                nPage = ($j("input[@name=vidListPage]").val()) ? Number($j("input[@name=vidListPage]").val()): 0;
                Get_VidList(nVidID, nVidCat, nPriSort, nVidSec, 4, (--nPage));
        });
}

var Init_VidTemp_Scripts = function() {

        nPriSort = $j("input[@name=currVidType]").val();
        nVidCat = $j("input[@name=currVidCat]").val();
        nVidID = $j("input[@name=currVidID]").val();
        nVidSec = $j("input[@name=currVidSec]").val();
        sVidTitle = $j("input[@name=currVidTitle]").val();

        $j("#vidFullDesc").hide();

        // Bookmark Control >>>
        $j("#vidTempBookmarkLink").click(function() {
                Add_Bookmark(nVidID, sVidTitle, nVidSec);
        });


        // EMail Dropdown >>>
        $j("input[@name=cancel]").click(function() {
                Reset_Email_Form();
                $j("#vidTempEmail").animate({height: 'toggle', opacity: 'toggle'}, "normal");
        });

        $j("input[@name=submit]").click(function() {
                var sComments = $j("textarea[@name=additionalComments]").val();
                var sFrom = $j("input[@name=fromEmailAddress]").val();
                var sTitle = $j("input[@name=currVidTitle]").val();
                var sTo = $j("input[@name=toEmailAddress]").val();
                var sUrl= $j("input[@name=currVidUrl]").val();
                var nVidID = $j("input[@name=currVidID]").val();
                var nVidSec = $j("input[@name=currVidSec]").val();

                //alert("to="+sTo+"&from="+sFrom+"&comments="+sComments+"&id="+nVidID+"&section="+nVidSec+"&title="+sTitle+"&url="+sUrl);
                $j.ajax({
                        type: "POST",
                        url: "/includes/Site/vidtemp_remote_email.php",
                        data: "to="+sTo+"&from="+sFrom+"&comments="+sComments+"&id="+nVidID+"&section="+nVidSec+"&title="+sTitle+"&url="+sUrl,
                        success: Handle_Email_Resp
                });/**/
        });

        $j("#emailTop a").click(function() {
                Reset_Email_Form();
                $j("#vidTempEmail").animate({height: 'toggle', opacity: 'toggle'}, "normal");
        });

        $j("#vidTempEmailLink").click(function() {
                Reset_Email_Form();
                $j("#vidTempEmail").animate({height: 'toggle', opacity: 'toggle'}, "normal", function() { $j("#vidTempEmail").dequeue(); });
        });

        // EMail Dropdown Positioning >>>
        var oEmail = $j("#vidTempEmail");
        var oEmailOff = $j("div#vidOptions").offset();
        var nOffsetTop = oEmailOff.top + 15;
        var nOffsetLeft = 610;
        oEmail.css("top", nOffsetTop);
        oEmail.css("left", nOffsetLeft);

        // Description Dropdown >>>
        $j("#vidSmallDesc p a").click(function() {
                $j("#vidSmallDesc").animate({height: 'toggle'}, "normal");
                $j("#vidFullDesc").animate({height: 'toggle'}, "normal").css("display", "block");
        });

        $j("#vidFullDesc p a").click(function() {
                $j("#vidSmallDesc").animate({height: 'toggle'}, "normal");
                $j("#vidFullDesc").animate({height: 'toggle'}, "normal").css("display", "block");
        });

        // Video List Controls >>>
        $j("#nextBtn").click(function() {
                nPage = ($j("input[@name=vidListPage]").val()) ? Number($j("input[@name=vidListPage]").val()): 0;
                Get_VidList(nVidID, nVidCat, nPriSort, nVidSec, 4, (++nPage));
        });

        $j("#prevBtn").click(function() {
                nPage = ($j("input[@name=vidListPage]").val()) ? Number($j("input[@name=vidListPage]").val()): 0;
                Get_VidList(nVidID, nVidCat, nPriSort, nVidSec, 4, (--nPage));
        });

};

