$(document).ready(function(){
	
	$('.fade').mosaic();
	
	/* ************************************************* LIVE SITE SEARCH */
	
	$('#searchForm').submit(function(){
		var searchbox = $("#s").val();
		var dataString = 'searchword='+ searchbox;
		if(searchbox==''){
			$("#resultsDiv").hide();
		}else{
			$.ajax({
			type: "POST",
			url: "search.php",
			data: dataString,
			cache: false,
			success: function(html){
				$("#resultsDiv").html(html).show();
			}
		});
		}return false; 
	});
	
	$("#s").keyup(function(){
		
		var searchbox = $("#s").val();
		var dataString = 'searchword='+ searchbox;
		
		if(searchbox==''){
			$("#resultsDiv").hide();
		}
	
	});
	
	$('html').click(function() {
	 	$("#resultsDiv").hide();
	 });
	
	 $('#page').click(function(event){
	     event.stopPropagation();
	 });
	
	
	jQuery(document).ready(function() {
	  jQuery("time.timeago").timeago();
	});
	
	
	$('#main').load('classes/assets/subscriber_count.php',function(){
															
	});
	
	
	$('div.bk-diamondslider').slider_plugin({timer_position: 'top-left',
		ken_burns_for_slides: false,
		show_direction: 'forward',
		socondary_nav_type: 'thumbs',
		secondary_nav_pos: 'bottom',
		secondary_nav_placement: 'outside',
		theme: 'modern',
		show_thumb_titles: false,
		slide_timeout: 3000,
		slide_animation: 3000,
		pause_on_hover: true
	});
	
	// Horizontal Sliding Tabs demo
	$('div#st_horizontal').slideTabs({  			
		// Options  			
		contentAnim: 'slideH',
		contentAnimTime: 1000,
		contentEasing: 'easeInOutExpo',
		tabsAnimTime: 600,
		tabSaveState: true	
	});	
	
	$("a.example1").fancybox();
	
	/* ************************************************* EMBED VIDEO SCRIPTING */
	
	$('.embedVideoButton').click(function(){
		$('#load_buttons_box').fadeIn();
		$('.check').hide();
		$('a#copy-description').zclip({
		    path:'js/ZeroClipboard.swf',
		    copy:function(){return $('input#embedShare').val();},
		    beforeCopy:function(){
		                $(this).next('.check').hide();
		            },
		    afterCopy:function(){
		                $('#callback-paragraph').css('background','green');
		                $(this).css('color','green');
		                $(this).next('.check').show();
		    }
		});
	});
	$('.close').click(function(){
		$('#load_buttons_box').fadeOut();
	});
	
	$(".share-embed-size-custom-width").keyup(function () {
	   	value = $(".share-panel-url").val(); 
	   	value = value.replace(/width\='\d*'/, "width='" + $(this).val() + "'");
	   	$(".share-panel-url").val(value);
	});
	
	$(".share-embed-size-custom-height").keyup(function () {
	   	value = $(".share-panel-url").val(); 
	   	value = value.replace(/height\='\d*'/, "height='" + $(this).val() + "'");
	   	$(".share-panel-url").val(value);
	});
	
	$('.share-embed-size').click(function(){
		if (!$(this).hasClass("custom")) {
		
			value = $(".share-panel-url").val(); 
			var width = $(this).attr('rel');
			var height = $(this).attr('title');
			
			value = value.replace(/height\='\d*'/, "height='" + height + "'");
			$(".share-panel-url").val(value);
			
			value = $(".share-panel-url").val();
			
			value = value.replace(/width\='\d*'/, "width='" + width + "'");
			$(".share-panel-url").val(value);
		
		}
		$('.share-embed-size').removeClass('selected')
		$(this).addClass('selected');
	
	});
	
	/* ************************************************* MOVIE RATING / WANT TO SEE SCRIPTING */
				
	$('#buzRating').rating("", {maxvalue:5, increment:.5});
	
	$('.star a').click(function() {
		$.ajax({
		  url: "userRating.php?add=1&rating=" + $(this).text() + "&movieID=" + $("#movieID").val(),
		  success: function(){
		  
		  }
		});
	});
	
	$(".cancel").click(function() {
		$.ajax({
		  url: "userRating.php?add=0&movieID=" + $("#movieID").val(),
		  success: function(){
		  }
		});
	});
	
	$("#seeYes").click(function() {
		$(".awesome").removeClass("awesome-selected");
		$(this).addClass("awesome-selected");
		
		$.ajax({
		  url: "wantToSeeRating.php?see=1&movieID=" + $("#movieID").val(),
		  success: function(){
		  
		  }
		});
		
		
	});
	
	$("#seeNo").click(function() {
		$(".awesome").removeClass("awesome-selected");
		$(this).addClass("awesome-selected");
		
		$.ajax({
		  url: "wantToSeeRating.php?see=0&movieID=" + $("#movieID").val(),
		  success: function(){
		  
		  }
		});
		
	});
	
});

/* ************************************************* BOXOFFICE DROPDOWN SCRIPT */
$("select").sb({
  ddCtx: function() { return $(this).closest("form"); }
});


/* ************************************************* MOVIE RELEASE DATES DROPDOWN SCRIPT */
$('.boxofficeDate').change(function() {
	var url = "http://boxofficebuz.com/boxoffice.php?date="+$('select.boxofficeDate').val();    
	$(location).attr('href',url);
});
$('.releaseYear').change(function() {
	var url = "http://boxofficebuz.com/movie_release.php?year="+$('select.releaseYear').val()+"&month="+$('select.releaseMonth').val();    
	$(location).attr('href',url);
});
$('.releaseMonth').change(function() {
	var url = "http://boxofficebuz.com/movie_release.php?year="+$('select.releaseYear').val()+"&month="+$('select.releaseMonth').val();    
	$(location).attr('href',url);
});


/* ************************************************* ADDTHIS TWITTER CONFIG */
var addthis_share = {
	templates: { twitter: '{{title}}: {{url}} via @boxofficeBUZ' }
}

var addthis_config = {
     ui_cobrand: "boxofficeBUZ.com",
     url_transforms : {
         shorten: {
             twitter: 'bitly'
         }
     },
     shorteners : {
         bitly : {
             login: 'geeksuiteinc',
             apiKey: 'R_dba1eb461cee02d2fbceb06e3b6bd794'
         }
     }
}


$('#terms').placeholder();
