/*
	Author: Talhah Mahomedy (tmahomedy@barrowsonline.com)
	Project: Barrows | Retail Marketing Specialists
	Function: Javascript for handling all movies events

	copyright 2011 Barrows Design And Manufacture
 */

var page_movies = 0;
var movie_count = '';

$(document).ready(function(){

    // Handle movie thumb mouseover
    $('.movies_thumb').live('mouseover', function(){
        $(this).children('div').css('background', 'url("include/images/play_icon.gif") no-repeat 282px -21px');
    });


    // Handle movie thumb mouseout
    $('.movies_thumb').live('mouseout', function(){
        $(this).children('div').css('background', 'url("include/images/play_icon.gif") no-repeat 282px 0px');
    });


    //Handle Movies Select
    $('.movies, .dark_close_movies, .barrows_movies, .au_movies').live('click', function(){
		 var movies;

		 if($(this).hasClass('au_movies')){
			 movies = $(this).next().attr('id');
		 }else{
			 movies = $(this).attr('id');
		 }

		 category_number = movies.replace('movies_', '');
		 category = 'movies';
		 background_color = '#303133';
		 goto_location(category, category_number, background_color, 0);

		 //Get Ajax and handle movie thumbs
		 $.ajaxQueue({
			url: 'include/content/movies/ajax_movies.php',
			async: true,
			type : 'GET',
			data: {
				 action : 'get_movies_thumb',
				 cache : new Date().getTime()
			 },
			 dataType: "html",
			 success: function(data){

				 $('.movies_list').html(data);
			 }
		 });
    });



    // Handle dark forward
    $('.dark_back_movies').live(mouse_touch, function(){
        var movie_id = $('.top_dark_right').attr('movie_id');
        movie_id = parseInt(movie_id.replace('openmovie_', '')) - 1;
        movie_count--;

        open_movie(movie_id, 'prev', movie_count, page_movies);
    });


    // Handle dark back
    $('.dark_forward_movies').live(mouse_touch, function(){
        var movie_id = $('.top_dark_right').attr('movie_id');
        movie_id = parseInt(movie_id.replace('openmovie_', '')) + 1;
        movie_count++;

        open_movie(movie_id, 'next', movie_count, page_movies);
    });


    // Handle open movie
    $('.open_movie, .movie_title').live('click', function(){
        var movie_id = $(this).attr('id');
        page_movies = parseInt($(this).attr('total_movies'));
        movie_count = parseInt($(this).attr('movie_count'));
        movie_id = parseInt(movie_id.replace('openmovie_', ''));
        open_movie(movie_id, 'next', movie_count, page_movies);
    });


});

function open_movie(id, direction, movie_count, page_movies){
    category_number = 2;
    category = 'movies';
    background_color = '#303133';
    goto_location(category, category_number, background_color, 0);

    //get movie to play
    $.ajaxQueue({
        url: 'include/content/movies/ajax_movies.php',
        async: true,
        type : 'GET',
        data: {
            action : 'get_movie_play',
            id: id,
            direction: direction,
            page_movies:page_movies,
            movie_count:movie_count,
            cache : new Date().getTime()
        },
        dataType: "html",
        success: function(data){
            $('.dark_banner').html(data);
        }
    });
}

