jQuery(document).ready( function(){

	
	jQuery('a.popup').click(function() {
		theHref = $(this).attr('href');
		theURL = '/popup/'+theHref;
		window.open(theURL,null,"height=500,width=500,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
//		window.open(theURL,"TreatmentTrials.com","menubar=0,resizable=1,width=500,height=500,scrollbars=1"); 
		return false;
	});
	
	jQuery('#tabs.ajax a').click(function() {
		jQuery('#TabContent').fadeTo(200,0.25);
		theLink = jQuery(this).attr('href');
		jQuery('#TabContent').load(theLink, function() {
			jQuery('#TabContent').fadeTo(0,1);
		});
		return false;
	});
	
	jQuery('.whatsThis').tipped().click(function() {
		return false;
	});
	
	jQuery('#Video2, #Video3, #Video4, #Video5, #Video6, #Tab2Content, #Tab3Content, #Tab4Content, #Tab5Content').hide();
	currentTab = '#Tab1Content';
	jQuery('#tabs li a').click(function() {
		jQuery('#tabs li').removeClass('selected');
		jQuery(this).parent().addClass('selected');
		jQuery(currentTab).hide();
		theShowTemp = jQuery(this).attr('href').split('#');
		theShow = '#'+theShowTemp[1];
		jQuery(theShow).show();
		currentTab = theShow;
		return false;
	});
	currentVideo = '#Video1';
	jQuery('#videoTabs li a').click(function() {
		toPause = jQuery(currentVideo+' object').attr('id');
		if ($.browser.webkit) {
		//	viddlerPause(toPause);
		}
		
		jQuery('#videoTabs li').removeClass('selected');
		jQuery(this).parent().addClass('selected');
		theShowTemp = jQuery(this).attr('href').split('#');
		theShow = '#'+theShowTemp[1];
		jQuery(currentVideo).hide();
		jQuery(currentVideo+' object').hide();
		jQuery(theShow).show();
		jQuery(theShow+' object').show();
		currentVideo = theShow;
		return false;
	});
	
	jQuery('#SendEnquiryButton').click(function() {
		jQuery('#enquiry').show();
		jQuery(this).hide();
	});
	

	//find all form with class jqtransform and apply the plugin
    jQuery("form.jqtransform").jqTransform();
    showID = jQuery('#WhatSelect').val();
	jQuery('.whereInputContainer').hide();
	jQuery('#'+showID).show();
    
    jQuery("#enquiry").hide();
    
	jQuery('.home #findTrialsPanel .jqTransformSelectWrapper, .home #findTrialsPanel .jqTransformSelectWrapper ul').css('width','215px');
	jQuery('.home #findTrialsPanel .jqTransformSelectWrapper ul').css('height','auto');
	jQuery('.home #findTrialsPanel .jqTransformSelectWrapper div span').css('width','180px');
	
	jQuery('#RestrictedVideo button').click(function() {
		if ( jQuery('#CheckIt').attr('checked') ) {
			jQuery('#RestrictedVideoBG, #RestrictedVideo').hide();
		} else {
			alert('You must check the box in order to play the video.');
		}
		return false;
	});
	
	jQuery('#WhatSelector, #WhatSelector ul li a').click(function() {
		showID = jQuery('#WhatSelect').val();
		jQuery('.whereInputContainer').hide();
		jQuery('#'+showID).show();
	});
	
	jQuery('#findTrialsPanel form').submit(function() {
		showID = jQuery('#WhatSelect').val();
		theWhat = jQuery('#findTrialsPanel form #WhatSelect option:selected').text();
		theWhere = jQuery('#findTrialsPanel form #' + showID + ' .selected').text();
		theID = jQuery('#findTrialsPanel form #' + showID + ' select').val();
		window.location = 'find-trials/?id='+ theID +'&what='+theWhat+'&where='+theWhere;
		return false;
	});
	
	theResultID = jQuery('#findTrialsPanel h2').attr('id');
	if ( theResultID == 110 || theResultID == 46 ) {
		jQuery('#WhatSelector ul li:nth-child(2) a').click();
		if ( theResultID ==  46 ) {
			jQuery('#metastatic-melanoma-to-the-liver-16 ul li:nth-child(2) a').click();
		}
		if ( theResultID ==  110 ) {
			jQuery('#metastatic-melanoma-to-the-liver-16 ul li:nth-child(1) a').click();
		}
	} else if ( theResultID == 143 ) {
		jQuery('#WhatSelector ul li:nth-child(1) a').click();
	}
	
	
});

function PauseMovie(movieName) 
{ 
    var fullMovieName = "viddler_" + movieName; 
    if (navigator.appName.indexOf("Microsoft") != -1) 
    { 
        // is IE or another Microsoft product that does not yet exist 
        if (navigator.appVersion.indexOf("MSIE 8.0") != -1) 
        { 
            //ie 8 
            var mv = document[fullMovieName]; 
            mv.viddlerPause(); 
            mv.viddlerSeek(0); 
        } 
        else if (navigator.appVersion.indexOf("MSIE 7.0") != -1) 
        { 
            //ie 7 
            var mv = document[fullMovieName]; 
            mv.viddlerPause(); 
            mv.viddlerSeek(0); 
        } 
        else 
        { 
            //ie 6 
            var mv = window[fullMovieName]; 
            mv.viddlerPause(); 
            mv.viddlerSeek(0); 
        } 
    } 
    else 
    { 
        //another browser like Firefox, Chrome, or Safari 
        var mv = document[fullMovieName]; 
        mv.viddlerPause(); 
    }

} 
