// Cufon.replace('.pointy, #content.base h1', { fontFamily: 'Pointy', hover: true });

jQuery.noConflict();

function assign_fitted() {jQuery('.clickable').fitted();}
  
function active_nav(){
  var path = location.pathname.substring(1);	
  jQuery('nav li a[href$="' + path + '"]').parent().addClass('nav-active'); // check path as typed exactly
  jQuery('nav li a[href$="' + path + '/"]').parent().addClass('nav-active'); // check path with an extra trailing slash added
}

function form_input_classes(){
    jQuery('input[type="text"]').addClass('text');
    jQuery('input[type="password"]').addClass('text');
    jQuery('input[type="checkbox"]').addClass('checkbox');
    jQuery('input[type="radio"]').addClass('radiobutton');
    jQuery('input[type="submit"]').addClass('submit');
    jQuery('input[type="image"]').addClass('buttonImage');
}

function form_labelize(){  
    jQuery(".labelize input:text").clearingInput(); 
}   

function lightbox(){
    var modal = jQuery.cookie('mw');
    //get the page url
    var locationHref = document.location.href;
    var bsdFrameworkUrlStructure = /\/page\//;
    var fbTab = /\/videos\/fb/;
    var mobileLightbox = DetectTierIphone();

    if (modal != 'visited' && mobileLightbox && document.referrer != "http://www.whymusicmatters.org/includes/mobile-splash" && bsdFrameworkUrlStructure.test(locationHref) != true)
    { 
        jQuery.cookie('mw','visited', { expires: 7, path: '/', domain: '.whymusicmatters.org'});
        window.location = 'http://www.whymusicmatters.org/includes/mobile-splash'; 
    }
    else if (modal != 'visited' && bsdFrameworkUrlStructure.test(locationHref) != true && fbTab.test(locationHref) != true) {
        jQuery.cookie('mw', 'visited', { expires: 7, path: '/', domain: '.whymusicmatters.org' });
        if(jQuery.support.changeBubbles){
            //not ie
            jQuery.fn.colorbox({
                href: '/includes/lightbox',
                width: '900px',
                height: '638px',
                iframe: true            
            });
            } else {
            //ie
            jQuery.fn.colorbox({
                href: '/includes/lightbox',
                width: '940px',
                height: '658px',
                iframe: true            
            });
            
        }
    }
}

function getVideo(videoID, videoTitle, videoWidth, videoHeight){
    var titleReplace = videoTitle;
    swfobject.embedSWF(
      'http://www.youtube.com/v/' + videoID + '?enablejsapi=1', 'embed', videoWidth, videoHeight, '9.0.0', false, false, {allowScriptAccess: 'always'});
//    jQuery('#playerContainer .text h3').text(titleReplace);
}

jQuery(document).ready(function() {
    active_nav();
    form_input_classes();
    form_labelize();
    assign_fitted();
/*    lightbox(); */

    jQuery('#home #videocarousel a.thumb').click(function(event){
        event.preventDefault();
        getVideo(this.id, this.title, 575, 305);
        return false;
    });

    jQuery('#fb #videocarousel a.thumb').click(function(event){
        event.preventDefault();
        getVideo(this.id, this.title, 440, 280);
        return false;
    });

    jQuery('.view-content #video-gallery a.thumb').click(function(event){
        event.preventDefault();
        getVideo(this.id, this.title, 900, 505);
        return false;
    });
});
