//++20111015
	var sortby1=0;
	var sortby2=0;
	var short1="1";
	var short2="1";
	var sortby = 0;

$(window).load(function() {
	$("#waitoverlay").css('display', 'none');
    $("#maincontent").css('display', 'block');   
});

$(document).ready(function(){
	//document.getElementById('select_sort1').value=0;
	//document.getElementById('select_sort2').value=0;
	//document.getElementById('short1').checked=false;
	//document.getElementById('short2').checked=false;
	
	sortby1=0;
	sortby2=0;
	short1=1;
	short2=1;

    $.ajax({
        type: "POST",
        url: "../../ajax_funcs/ga_ajax_courses.php",
        data: "select_sort1="+sortby1+"&short1="+short1+"&region_name="+region_name+"&domain="+domain+"&session_course="+session_course+"&session_hotel="+session_hotel,
        success: function(data){
	        //alert(data);
        	$("#course_list").html(data);
        }
    });
	//var sortby=$(this).val();
	//alert (sortby);
    $.ajax({
        type: "POST",
        url: "../../ajax_funcs/ga_ajax_hotels.php",
        data: "select_sort2="+sortby2+"&short2="+short2+"&region_name="+region_name+"&domain="+domain+"&session_course="+session_course+"&session_hotel="+session_hotel,
        success: function(data){
	        //alert(data);
        	$("#hotel_list").html(data);
        }
    });
});	

	$('#select_sort1').live('change',function(){
		 
		sortby1=$(this).val();
		//alert (sortby);
	    $.ajax({
	        type: "POST",
	        url: "../../ajax_funcs/ga_ajax_courses.php",
	        data: "select_sort1="+sortby1+"&short1="+short1+"&region_name="+region_name+"&domain="+domain+"&session_course="+session_course+"&session_hotel="+session_hotel,
	        success: function(data){
		        //alert(data);
	        	$("#course_list").html(data);
	        }
	    });
	});
	$('#select_sort2').live('change',function(){
		sortby2=$(this).val();
		//alert (sortby);
	    $.ajax({
	        type: "POST",
	        url: "../../ajax_funcs/ga_ajax_hotels.php",
	        data: "select_sort2="+sortby2+"&short2="+short2+"&region_name="+region_name+"&domain="+domain+"&session_course="+session_course+"&session_hotel="+session_hotel,
	        success: function(data){
		        //alert(data);
	        	$("#hotel_list").html(data);
	        }
	    });	
	});	

	$('.short1_radio').live('change',function() {
	//$('input:radio[name=short1]').live('click',function(){
		short1 = $('input[name=short1]:radio:checked').val();

	    $.ajax({
	        type: "POST",
	        url: "../../ajax_funcs/ga_ajax_courses.php",
	        data: "select_sort1="+sortby1+"&short1="+short1+"&region_name="+region_name+"&domain="+domain+"&session_course="+session_course+"&session_hotel="+session_hotel,
	        success: function(data){
		        //alert(data);
	        	$("#course_list").html(data);
	        }
	    });
	    
	});
	$('.short2_radio').live('change',function() {
	//$('input:radio[name=short2]').live('click',function(){
		short2 = $('input[name=short2]:radio:checked').val();
	    $.ajax({
	        type: "POST",
	        url: "../../ajax_funcs/ga_ajax_hotels.php",
	        data: "select_sort2="+sortby2+"&short2="+short2+"&region_name="+region_name+"&domain="+domain+"&session_course="+session_course+"&session_hotel="+session_hotel,
	        success: function(data){
		        //alert(data);
	        	$("#hotel_list").html(data);
	        }
	    });
	});	

	$('.course_checkboxes').live('change',function() {
//	$('input:checkbox[name="session_course[]"]').live('click',function() { 
			if ($(this).attr('checked'))
			{
				if (session_course=="" || session_course=="|"){
					session_course = "|" + $(this).val()+"|";
				}
				else {
	        		session_course = session_course + $(this).val()+"|";
	        	}
	        }
	        else
	        {
	        	session_course=session_course.replace("|" + $(this).val()+"|","|");
	        }
	 });
	$('.hotel_checkboxes').live('change',function() { 
//	$('input:checkbox[name="session_hotel[]"]').live('click',function() { 
			if ($(this).attr('checked'))
			{
				if (session_hotel=="" || session_hotel=="|")
					session_hotel = "|" + $(this).val()+"|";
				else 			
	        		session_hotel = session_hotel+ $(this).val()+"|";
	        }
	        else
	        {
	        	session_hotel=session_hotel.replace("|" + $(this).val()+"|","|");
	        }
	 });

	 
var intval="";
var intval1="";
var pic_real_width;
var pic_real_height;

function select_image1(id,type){
    $.ajax({
        type: "POST",
        url: "../../ajax_funcs/slideshow.php",
        data: "id="+id+"&section_name="+type,
        success: function(data){	                	        	
			//$("#insert_img_here").html("<center><img src='"+image+"' alt='No Image' border='0' /></center>");
			// new Boxy($('#insert_img_here').wrapInner('<div style="width: 320px;"></div>').html(),{modal:true,title:'Image'});
			$("#insert_images").html(data);
            $('a[rel=album]').fancybox({
                'transitionIn'		: 'none',
                'transitionOut'		: 'none',
                'titlePosition'             : 'inside',
                'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
                        return '<span id="fancybox-title-inside">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
                }
            });
            $('a[rel=album]:first').trigger('click');
        }
    });
    //++slides dialog++//
	//showDialog();
	//if (intval1=='')	
	//	intval1= setInterval( 'first_slideSwitch()', 600 );
	//--
}


function select_image(id,type){
    $.ajax({
        type: "POST",
        url: "../../ajax_funcs/slideshow.php",
        data: "id="+id+"&section_name="+type,
        success: function(data){
	        //alert(data);
        	$("#slideshow").html(data);        	
        }
    });
	
	//$("#insert_img_here").html("<center><img src='"+image+"' alt='No Image' border='0' /></center>");
	// new Boxy($('#insert_img_here').wrapInner('<div style="width: 320px;"></div>').html(),{modal:true,title:'Image'});
    alert("abc");
    $('#slideshow').fancybox({
        'transitionIn'		: 'none',
        'transitionOut'		: 'none',
        'titlePosition'             : 'inside',
        'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
                return '<span id="fancybox-title-inside">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });    
    
	//showDialog();
	if (intval1=='')	
		intval1= setInterval( 'first_slideSwitch()', 600 );

        //intval= setInterval( 'slideSwitch()', 3000 );    

}
function showDialog() {
	//$("#slideshow").fadeIn(400);   
	 
    $("#slideshow").dialog({
        width:'310',
	    height:'290',                        
    	show: 'fade',
        hide: 'fade',                
        position: 'center',
        open: function (event, ui) {
            $('#slideshow').css('overflow', 'hidden');
            
        }        
    });  

    //$('#slideshow').dialog('open');
    $("#overlay").show();
}
$("#slideshow").live('dialogclose', function(e) {
	if (intval1!='')
		clearInterval( intval1);
	intval1='';
	if (intval!='')	
		clearInterval( intval);
	intval='';
	$("#overlay").hide();
	//e.preventDefault();
});	 
function first_slideSwitch() {
	//alert('1');
    var $active = $('#slideshow IMG.active');
	$active.animate({opacity: 0.0}, 20);
   	$img_first = $('#slideshow IMG:first');     	
    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 500, function() {
            $active.removeClass('active last-active');            
        });

    $next.removeAttr('height');
    $next.removeAttr('width');
    if (($next.width()>280)||($next.height()>90))
    {
        pic_real_width = $next.width();
        pic_real_height = $next.height()+40;
		$("#slideshow").dialog('option','width',pic_real_width);
	    $("#slideshow").dialog('option','height',pic_real_height);
	    //alert(pic_real_width+" "+pic_real_height);
    }    
	if (intval1!='')
	{
    	clearInterval(intval1);
    	intval1='';
    }
    if (intval=='')
    	intval= setInterval( 'slideSwitch()', 3000 );
}    
function slideSwitch() {
	
    var $active = $('#slideshow IMG.active');
	$active.animate({opacity: 0.0}, 20);
    if ( $active.length == 0 ){
    	$img_first = $('#slideshow IMG:first');
    	$img_last = $('#slideshow IMG:last');
    	if ($img_first==$img_last)
    		$active = $('#slideshow IMG:first');
    	else
         	$active = $('#slideshow IMG:last');
     	
    }
    //alert("next:"+$active.next().length);       
    // use this to pull the images in the order they appear in the markup
    
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');
	if ($next.attr('id')=='0')
	{		
		$next =  $next.next().length ? $next.next()
		        : $('#slideshow IMG:first');
	}

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 500, function() {
            $active.removeClass('active last-active');            
        });

    $next.removeAttr('height');
    $next.removeAttr('width');
    if (($next.width()>280)||($next.height()>90))
    {
        pic_real_width = $next.width();
        pic_real_height = $next.height()+40;
		$("#slideshow").dialog('option','width',pic_real_width);
	    $("#slideshow").dialog('option','height',pic_real_height);
	    //alert(pic_real_width+" "+pic_real_height);
    }    

}    
    function select_video(id){
        $.getJSON('../../ajax_funcs/getvideo.php?id='+id,function(json){
            switch(json['file_type']){
                case 'Video':
                    load_flash('/images/golf_course/'+json['file_name'],json['file_title']);
                    new Boxy($('#insert_here').wrapInner('<div style="scaling: fit;"></div>').html(),{modal:true,draggable: true, fixed:false,title:'Video'});
                    break;
                case 'youtube':
                    $('#insert_here').html('<div>'+json['embed_code']+'<p>'+json['description']+'</p></div>');
                    new Boxy($('#insert_here').wrapInner('<div style="scaling: fit;width: 640px;"></div>').html(),{modal:true,draggable: true, fixed:false, title:'Video'});
                    break;
            }
            	
        });
    }
    function load_flash(send_value, video_title){
        insert_content  = "";
        insert_content += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="343" height="392" id="video_container">';
        insert_content += '<param name="movie" value="/video.swf?videosrc='+send_value+'&vtitle='+video_title+'" />';
        insert_content += '<param name="wmode" value="transparent" />';
        insert_content += '<param name="quality" value="high">';
        insert_content += '<embed src="/video.swf?videosrc='+send_value+'&vtitle='+video_title+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="343" height="392" wmode="transparent" name="video" id="video"></embed>';
        insert_content += '</object>';

        $("#insert_here").html(insert_content);
    }

    

