/* --- Start /home/httpd/public/app_frame2/webroot/js/VVTabs.js --- */

//-----------------------------------------------------------------------------
/*
 * Tab control class
 */
//-----------------------------------------------------------------------------
function TabSet(parentId)
{
    //-------------------------------------------------------------------------
    /*
    ** Constructor code
    */
    this.tabs = new Array();
    this.parentElement = document.getElementById(parentId);
    this.tabSet = document.createElement('ul');
    this.tabSet.className = 'tabs';
    this.parentElement.appendChild(this.tabSet);
    this.activeIndex = null;
    this.usePlaceholder = false;
    //-------------------------------------------------------------------------
    /*
    ** Add a tab to the tabset
    **
    ** @param tabName - Name of tab
    ** @param contentId - Id of element to show/hide on click of tab
    ** @param active - Make this tab active immediately
    */
    this.addTab = function(tabName, contentId, active)
    {
        var tab = document.createElement('li');
        tab.innerHTML = tabName;
        tab.contentBodyElementId = contentId;
        tab.tabSet = this;
        tab.index = this.tabs.length;
        tab.classExtra = contentId;
        this.tabSet.appendChild(tab);
        this.tabs.push(tab);
        if(active)
        {
            tab.className = 'tab active ' + tab.classExtra;
        }
        else
        {
            tab.className = 'tab inactive ' + tab.classExtra;
        }
        tab.onclick = function()
        {
            var tabSet = tab.tabSet;
            for(i = 0; i < tabSet.tabs.length; i++)
            {

                var contentBody = document.getElementById(tabSet.tabs[i].contentBodyElementId);
                if(tab != tabSet.tabs[i] && tabSet.tabs[i].className != 'tab placeholder')
                {
                    tabSet.tabs[i].className = 'tab inactive ' + tabSet.tabs[i].classExtra;
                    //contentBody.hide();
                    contentBody.style.display = 'none';
                }
                else if (tabSet.tabs[i].className != 'tab placeholder')
                {
                    tabSet.tabs[i].className = 'tab active ' + tabSet.tabs[i].classExtra;
                    //contentBody.show();
                    contentBody.style.display = '';
                }
            }
            if(tabSet.activeIndex != null)
            {
                tabSet.orderTabs(tab.index);
            }
        }
    }

    this.activateTab = function(tabName)
    {
        var index = 0;
        for(i = 0; i < this.tabs.length; i++)
        {
            var contentBody = document.getElementById(this.tabs[i].contentBodyElementId);
            if(this.tabs[i].innerHTML == tabName)
            {
                this.tabs[i].className = 'tab active ' + this.tabs[i].classExtra;
                contentBody.style.display = '';
                index = i;
            }
            else
            {
                this.tabs[i].className = 'tab inactive '  + this.tabs[i].classExtra;
                contentBody.style.display = 'none';
            }

        }
        if(this.activeIndex != null)
        {
            this.orderTabs(index);
        }
    }

    this.setActiveIndex = function(activeIndex)
    {
        this.activeIndex = activeIndex;
        var index = 0;
        for(i = 0; i < this.tabs.length; i++)
        {
            if(this.tabs[i].className == 'tab active ' + this.tabs[i].classExtra)
            {
                index = i;
                break;
            }
        }
        this.orderTabs(index);
    }

    this.orderTabs = function(startIndex)
    {
        if(this.activeIndex != null)
        {
            for(i = 0; i < this.tabs.length; i++)
            {
                this.tabSet.removeChild(this.tabs[i]);
            }
            if (this.usePlaceholder) {
                for(i = 0; i < this.tabs.length; i++) {
                    if (this.tabs[i].className == 'tab placeholder') {
                        this.tabs.splice(i, 1);
                    }
                }
            }
            var index = this.activeIndex + startIndex >= this.tabs.length ? this.activeIndex + startIndex - this.tabs.length : this.activeIndex + startIndex;
            if (this.usePlaceholder) {
                var placeholder = document.createElement('li');
                placeholder.className = 'tab placeholder';
                var placeholderIndex = index + 1 >= this.tabs.length + 1 ? 0 : index + 1;
                this.tabs.splice(placeholderIndex, 0, placeholder);
            }
            for(i = 0; i < this.tabs.length; i++)
            {
                this.tabSet.appendChild(this.tabs[index]);
                index = index + 1 >= this.tabs.length ? 0 : index + 1;
            }
        }
    }
}

/* --- End /home/httpd/public/app_frame2/webroot/js/VVTabs.js --- */
/* --- Start /home/httpd/public/app_frame2/webroot/js/PageViews.js --- */

function TrackPageView(objid, type, sendToFriend)
{
    // Tracker webservice url
    var url = '/services/trackPageView/' + objid + '/' + type + '/' + sendToFriend;
    $.getJSON(
        url,
        function(transport,json){
            if(json){
                // Leave empty for now, it's just transparent tracking
                if(json.status == 'OK'){
                
                }else if(json.status == 'ERROR'){

                }
            }
        }
    );
}

$(document).ready(function(){
    var tracker = $( "#TrackerForm" );
    if (tracker.length > 0) {
        var objid = tracker.children("input[name='objid']").val(); 
        var type = tracker.children("input[name='type']").val();
        var sendToFriend = tracker.children("input[name='sendToFriend']").val();
        TrackPageView(objid, type, sendToFriend);  
    }
});


/* --- End /home/httpd/public/app_frame2/webroot/js/PageViews.js --- */
/* --- Start /home/httpd/public/app_frame2/webroot/js/SearchFilms.js --- */

$(document).ready(function() {
    var defaultKeywords = 'Keywords';
    var defaultZipCode  = 'Zip Code';

    $('.search_keywords').val(defaultKeywords);
    $('.search_zipcode').val(defaultZipCode);

    $('.search_keywords').focus(function() {
        if ($('.search_keywords').val() == defaultKeywords) {
            $('.search_keywords').val('');
        }
    });
    $('.search_zipcode').focus(function() {
        if ($('.search_zipcode').val() == defaultZipCode) {
            $('.search_zipcode').val('');
        }
    });

    $('.search_form').submit(function() {
        if ($('.search_keywords').val() == defaultKeywords) {
            $('.search_keywords').val('');
        }
        if ($('.search_zipcode').val() == defaultZipCode) {
            $('.search_zipcode').val('');
        }

        // if we have a zip, we go to /movies/showtimes/now-showing regardless of
        // presence of keyword
        if ($('.search_zipcode').val() != '') {
            $('.search_form').attr('action', '/movies/showtimes/now-showing');
            $('.search_form').attr('method', 'get');
        }

        return true;
    });
});


/* --- End /home/httpd/public/app_frame2/webroot/js/SearchFilms.js --- */
/* --- Start /home/httpd/public/app_frame2/webroot/js/DiggWidget.js --- */

function showUpcoming () {
	var p = document.getElementById('digg-widget-container-popular').style;
	var u = document.getElementById('digg-widget-container-upcoming').style;
	var btnP = document.getElementById('diggPopular');
	var btnU = document.getElementById('diggUpcoming');

	p.display = "none";
	u.display = "block";
	btnP.src = "/img/popularOff.png";
	btnU.src = "/img/upcomingOn.png";
}

function showPopular () {
	var p = document.getElementById('digg-widget-container-popular').style;
	var u = document.getElementById('digg-widget-container-upcoming').style;
	var btnP = document.getElementById('diggPopular');
	var btnU = document.getElementById('diggUpcoming');

	p.display = "block";
	u.display = "none";
	btnP.src = "/img/popularOn.png";
	btnU.src = "/img/upcomingOff.png";
}

/* --- End /home/httpd/public/app_frame2/webroot/js/DiggWidget.js --- */
/* --- Start /home/httpd/public/app_frame2/webroot/js/TopStoriesWidget.js --- */

$(document).ready(function(){
	$('.top_stories_jCarouselLite').show();
	$('.top_stories_jCarouselLite').jCarouselLite({btnNext: ".top_stories_jCarouselLite_next", btnPrev: ".top_stories_jCarouselLite_prev", visible:4});
});


/* --- End /home/httpd/public/app_frame2/webroot/js/TopStoriesWidget.js --- */
/* --- Start /home/httpd/public/app_frame2/webroot/js/Comments.js --- */


$(document).ready(function(){	
	if($('.CommentShowButton').length){
		$('.CommentShowButton').click(function(){
			var isOpen = (document.getElementById('CommentsContainer').style.display == 'none') ? false : true;
			if(isOpen == false){
				$('#CommentsContainer').slideDown('slow');			
			}else{
				$('#CommentsContainer').slideUp('slow');				
			}
			//If we're the top CommentsShowButton, we need to refocus the window 
			$('#CommentsContainer').focus();
		});		
	}
	
	if($('#CommentCreateButton').length){
		$('#CommentCreateButton').click(function(){
			var isOpen = (document.getElementById('CommentCreateContainer').style.display == 'none') ? false : true;			
			if(isOpen == false){
				$('#CommentCreateContainer').slideDown('slow');				
				document.getElementById('CommentCreateButton').innerHTML = '<a>Cancel Creating Comment</a>';
			}else{
				$('#CommentCreateContainer').slideUp('slow');		
				document.getElementById('CommentCreateButton').innerHTML = '<a>Post Comment</a>';				
			}
		});
	}
    $( "#CommentAddForm input#name, #CommentAddForm input#email, #CommentAddForm #city, #CommentAddForm #comment" ).focus( function() {
        if ( $("#captcha_container_div").html().length == 0 ) {
            var SESSION_ID = $("#sessid").val();
            $("#captcha_container_div").append( "<img src='/comments/captcha/?" + SESSION_ID + "' />" );
        }
    });
	
//	if($('#CommentsShowAllButton').length){
		$('#CommentsShowAllButton').click(function(){
			var id 		= $('#CommentsObjid').val();
			var type	= $('#CommentsType').val();
			var url		= '/comments/AjaxCommentsForIdAndType/'+id+'/'+type+'/'			
			$('#CommentsList').after('<img src="/img/ajax-loader.gif" class="CommentsFeedbackImg">');
			$('#CommentsList').load(url, '', function(responseText, textStatus, XMLHttpRequest){
				$('#CommentsListContainer').hide();
				$('.CommentsHeader').hide();
				$('#CommentsList').html(responseText);
				$('.CommentsFeedbackImg').hide();
				$('#CommentsListContainer').slideDown('slow');
			});
		});
//	}
	
	if($('#CommentAddForm').length){
		$('#CommentAddForm').submit(function(){
			$('.CommentInputError').hide();
			var fields = {
				name:'Name is required',
				email:'Email is required',
				//state:'State is required',
				//age:'Age is required',
				comment:'Give us your comment',
				captcha:'Please validate that your a human'
			};
			var errors = [];
			for(fieldName in fields){
				if($('#'+fieldName).val().length < 1){
					$('#'+fieldName+'lbl').after('<span class="CommentInputError"><img src="/img/required.png">'+fields[fieldName]+'</span>');
					$('#'+fieldName).blur(function(){
						$('#'+fieldName+' .CommentInputError:first').hide();
					});
					errors.push(fieldName);
				}
				if(fieldName == 'email' && $('#'+fieldName).val().length > 0){
					var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if(!$('#'+fieldName).val().match(emailRegEx)){					
							$('#'+fieldName+'lbl').after('<span class="CommentInputError"><img src="/img/required.png">Your E-mail is Invalid</span>');
							$('#'+fieldName).blur(function(){
								$('#'+fieldName+' .CommentInputError:first').hide();
							});						
							errors.push(fieldName);
					}
				}
			}
			if(errors.length > 0){
				return false;
			}
			$('#CommentAddForm INPUT:enabled, #CommentAddForm TEXTAREA:enabled, #CommentAddForm SELECT:enabled').attr('disabled', true);
			$('#CommentAddForm').after('<img src="/img/ajax-loader.gif" class="CommentsFeedbackImg">');
			
			var id 		= $('#CommentsObjid').val();
			var type	= $('#CommentsType').val();
            var SESSION_ID = $("#sessid").val();
			var url		= '/comments/AjaxAddCommentForIdAndType/'+id+'/'+type+'/?' + SESSION_ID
			
			$.post(url, {
				name:$('#name').val(),
				email:$('#email').val(),
				city:$('#city').val(),
				//state:$('#state').val(),
				//age:$('#age').val(),
				comment:$('#comment').val(),
				captcha:$('#captcha').val()
				}, function(responseText){
					$('.CommentsFeedbackImg').hide();		
					$('#CommentAddForm INPUT, #CommentAddForm TEXTAREA, #CommentAddForm SELECT').attr('disabled', false);	
				
					//if(document.getElementById('JASONDEBUGDIV'))
						//document.getElementById('JASONDEBUGDIV').innerHTML = responseText;					
					
				
					var now = new Date();
                    var SESSION_ID = $("#sessid").val();
                    $("#captcha_container_div").html( "" );
                    $("#captcha_container_div").append( "<img src='/comments/captcha/?" + SESSION_ID + "' />" );
					if(responseText == 'CAPTCHA'){				
						$('#captcha').after('<span class="CommentInputError"><img src="/img/required.png">Validation Failed!!</span>');
						return;
					}
					if(responseText == 'OK'){
                        $('#CommentAddForm INPUT, #CommentAddForm TEXTAREA, #CommentAddForm SELECT').not('#CommentAddSubmit, #CommentsObjid, #CommentsType').val('');
						var id 		= $('#CommentsObjid').val();
						var type	= $('#CommentsType').val();
						var url		= '/comments/AjaxCommentsForIdAndType/'+id+'/'+type+'/5/';
						$('#CommentsList').load(url, '', function(responseText, textStatus, XMLHttpRequest){
							$('.CommentsHeader').hide();						
							$('#CommentsList').html(responseText);
							//Have to add the click element to the new CommentsShowAllButton we just loaded
							if($('#CommentsShowAllButton').length){
								$('#CommentsShowAllButton').click(function(){
									var id 		= $('#CommentsObjid').val();
									var type	= $('#CommentsType').val();
									var url		= '/comments/AjaxCommentsForIdAndType/'+id+'/'+type+'/'			
									$('#CommentsList').after('<img src="/img/ajax-loader.gif" class="CommentsFeedbackImg">');
									$('#CommentsList').load(url, '', function(responseText, textStatus, XMLHttpRequest){
										$('#CommentsListContainer').hide();
										$('.CommentsHeader').hide();
										$('#CommentsList').html(responseText);
										$('.CommentsFeedbackImg').hide();
										$('#CommentsListContainer').slideDown('slow');
									});
								});
							}												
						});	 //end CommentsList.load(...){}														
						return false;
					} // end if(responseText == 'OK'){}			
					
					if(responseText == 'ERROR'){
						alert('An error has occured, please try again later.');
						return false;
					}
									
				} //end anon function(responseText){}
			);
			
			return false;
		});
	}
	
});


/* --- End /home/httpd/public/app_frame2/webroot/js/Comments.js --- */
/* --- Start /home/httpd/public/app_frame2/webroot/js/text_size.js --- */

$(document).ready(function(){
    $('#text_size_sm').click(function(){
        //Would like to remove all classes but there is no other identifier for this div
        $('.content_body').removeClass('med');
        $('.content_body').removeClass('lg');
        $('.content_body').addClass('sm');
    });

    $('#text_size_med').click(function(){
        $('.content_body').removeClass('sm');
        $('.content_body').removeClass('lg');
        $('.content_body').addClass('med')
    });

    $('#text_size_lg').click(function(){
        $('.content_body').removeClass('sm');
        $('.content_body').removeClass('med');
        $('.content_body').addClass('lg')
    });

    return false;
});

/* --- End /home/httpd/public/app_frame2/webroot/js/text_size.js --- */
/* --- Start /home/httpd/public/app_frame2/webroot/js/ContentView.js --- */

$(document).ready( function() {
    $( ".commentlink a" ).click( function() {
        $( "#CommentsContainer").slideDown();
    });
});

/* --- End /home/httpd/public/app_frame2/webroot/js/ContentView.js --- */
/* --- Start /home/httpd/public/app_frame2/webroot/js/AdIndexTower.js --- */

$(document).ready(function(){
    var section = $("#AdIndexTower").children("form").children("input[name='section']").val();
    var limit = $("#AdIndexTower").children("form").children("input[name='limit']").val();
    if ( section ) {
        $.get(
            '/adIndex/ajaxTower/' + section + '/' + limit,
            function (data) {
                $('#AdIndexTower').append(data);
            }
        );
    }
});


/* --- End /home/httpd/public/app_frame2/webroot/js/AdIndexTower.js --- */


/* Generated at 2010-03-18 17:03:09 */
