function is_ie(){
	return (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER')?true:false;
}

function print_iframe(element_id){
	if (is_ie()){
		document.element_id.focus();
		document.element_id.print();
	}else{
		window.frames['element_id'].focus();
		window.frames['element_id'].print();
	}
}

//create a iframe that pulls in the card pdf and then call print on it
function print_card(type,id){
	if($('#print_container') == null){
		$('#container').append('<iframe id="print_container" />');
	}
	if(type == 'user'){
		$("#print_container").attr('src', '/cards/print.card.pdf/uid/'.id);
	}else{
		$("#print_container").attr('src', '/cards/print.card.pdf/cid/'.id);
	}
}

function toggle_other(el,target_id){
	if(el.value == ''){
		$(target_id).show();	
	}else{
		$(target_id).hide();
	}
}

function openPage(url) {
        var newwindow=window.open(url,'name');
        return false;
 }

function submit_upload_form(button_id,form_id){
	$(button_id).active = false;
	$(button_id).html("<span><em>Saving...</em></span>");
	$(form_id).submit();
}

function toggleShowAll(collapsed_div, expanded_div, more_link, less_link) {
	var c_div = document.getElementById(collapsed_div);
	var e_div = document.getElementById(expanded_div);
	var more_link = document.getElementById(more_link);
	var less_link = document.getElementById(less_link);
	
	if (c_div.style.display == 'none') {
		e_div.style.display = 'none';
		c_div.style.display = '';
		less_link.style.display = 'none';
		more_link.style.display = '';

	}
	else {
		c_div.style.display = 'none';
		e_div.style.display = '';
		more_link.style.display = 'none';
		less_link.style.display = '';
	}
}

function nextYoutubeVideo(video_id,card_id){
	//update video details
	var path = '/widget/get.video.details/vid/'+video_id+'/cid/'+card_id;
	//alert(path);
	$("#media_details_content").html('<div class="blank_portfolio">Loading...</div>');
	 $.ajax({
	   type: "GET",
	   url: path,
	   success: function(msg){
	   		$("#media_details_content").html(msg);
	   }
	 });
	 //refresh ads if need be
	 
}

function toggleChannelDrawer() {
	$("#channels_container").slideToggle();
	$("#horizontal_ad_top").toggle();
}

$(function() {
	$("#channels_link").click(function(event) {
		event.preventDefault();
		$("#channels_container").slideToggle();
		$("#horizontal_ad_top").toggle();
	});

	$("#channels_container a#close").click(function(event) {
		event.preventDefault();
		$("#channels_container").slideUp();
		$("#horizontal_ad_top").show();
	});
});


try{
	// Facebox init
	jQuery(document).ready(function($) {
		$('a[rel*=facebox]').facebox();
	})
}catch(e){}


var Casting = function(){
	
	return{
		deleteCasting : function(casting_id){
			var confirm_delete = window.confirm("Are you sure you want to delete this casting?");
			if (confirm_delete)
				window.location = '/casting/delete.casting/cid/' + casting_id;
		}
	}
}();

function selectVideo(video_id, youtube_id) {
	var input_name = '#facebox #video_' + video_id + '_youtube_id';
	$(input_name).val(youtube_id);
	$("#facebox .replace_video").css("border-color","white");
}

/*
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}*/
