/*///////////////////////////////////////////////////////////////////
    File        ipak.js
    Author      Richard Leland
    Purpose     Site-wide UI javascript enhancements
    Requires    jquery 1.2.6
                jqueryUI 1.6
///////////////////////////////////////////////////////////////////*/

// TODO: shadowbox code, and Bob's XHR code

$(document).ready(function(){

    // navigation accordion
    // TODO: figure out how to have the accordion not animate on page load
    $('#nav-channel').accordion({
        header: 'a.toggler-link',
        autoHeight: false,
        alwaysOpen: false,
        active: false
    });
    // open the appropriate accordion item
    $('#nav-channel').accordion('activate', 'a.current');
    
    // determine if we're on the login page
    if($('body').hasClass('login')){
        var emailField = $('#id-email');
        var passField = $('#id-password');
        
        // hide the error msgs initially
        $('.error-msg').hide();
        
        // focus on the username field
        emailField.focus();
        
        // perform some simple validation
        $('#frm-login').submit(function(){
            var emailValue = jQuery.trim(emailField.val());
            var passValue = jQuery.trim(passField.val());
            
            if(emailValue != '' && passValue != ''){
                return true;
            } else {
                if(emailValue == ''){
                    $('#id-email-msg').fadeIn("medium").fadeOut(2000);
                    emailField.focus();
                }
                if(passValue == ''){
                    $('#id-password-msg').fadeIn("medium").fadeOut(2000);
                }
                return false;
            }
        });
    }
    
    // determine if the page has the search field
    if($('#id-search')){
        var strSearchField = 'Search...';
        var searchField = $('#id-search');
        // tell the search field what to do onfocus
        searchField.bind('focus', function(){
            if(this.value == strSearchField) this.value = '';
        });
        // tell the search field what to do onblur
        searchField.bind('blur', function(){
            if(this.value == '') this.value = strSearchField;
        });
    }
    
    // tabs for the programming highlights pages
    if($('#tabs-container')){
        $('#tabs-container > ul').tabs();
    }
    
    // Open the schedule in a new window
    $('a[href*=includes/schedule.cfm]').click(function(event) {
    	var dialogdiv;
    	
    	// Prevent the link from opening by itself
    	event.preventDefault();
    	
		// Load the dialog contents and create the dialog
    	dialogdiv = $("<div id='schedule'/>").load($(this).attr("href")).dialog({
			width: '943px',
			height: '90%',
			modal: true,
			resizable: false,
			draggable: false,
			bgiframe:true,
			overlay: {
				opacity: 0.5,
				background: "black"
			}
		});
    	
    	// Explicitly set the height of the #schedule div.
    	$("#schedule").height("100%");
    	
    	// Get rid of the dialog's close button
    	$(".ui-dialog-titlebar-close > span").empty();
    	
    	// When the schedule dialog is open, add the schedule-open class to the body tag (for print layout)
    	$("body").addClass("schedule-open");
    });

	if ($('#flash-adn').length) {
                        $('#flash-adn').load('/systemimages/ADN/adndownload-min.cfm?networkid=' + $('#networkid').text(), function(){launchADN();});
        }    

	if ($('#video_roi_feedback_dynamic_link').length) {
		//$('#video_roi_feedback_dynamic_link').append('You can take the video ROI feedback survey <a href="#" id="videoroifeedback">here</a>');
		$('#video_roi_feedback_dynamic_link').append('<div><p><a href="#" id="videoroifeedback">CLICK HERE</a> to share how you are using Discovery Networks video resources to help secure new revenue and drive your business.</p><p>As a thank-you for helping us better understand and meet your video resource needs, you&#146;ll receive a <span style="font-weight=bold">special Discovery gift</span>.</p></div>');
	}

	if ($('#videoroifeedback').length) {
		$('#videoroifeedback').click(function(){
			DA.launchVideoROIFeedbackSurveyPrompt(this);
		});
	}
	
	if ($('#roilaunchtest').length) {
		$('#roilaunchtest').click(function(){
			DA.launchVideoROIFeedbackSurveyPrompt(this);
		});
	}	
});

