/* $Id: scripts.js 6597 2010-03-01 16:04:06Z borutk $ */

var response = true;

function createplayer(theFile, go, id) {
	var so = new SWFObject('/plugins/flv_player/player.swf','mpl','320','240','9');
	so.addParam('allowscriptaccess','always');
	//so.addVariable("file",theFile);
	so.addParam('allowfullscreen','true');
	so.addParam('stretching','none');
	so.addParam('wmode','transparent');
	so.addParam('skin','/plugins/flv_player/skins/modieus.swf');
    //so.addParam('flashvars','skin=/plugins/flv_player/skins/modieus.swf');
    so.addParam('flashvars','file='+ theFile +'&autostart=true&skin=/plugins/flv_player/skins/modieus.swf');
    
	if (go) { so.addVariable("autostart","true"); }
	so.write('player' + id);
	//console.log(theFile);
}

function createaudioplayer(theFile, go, id) {
	var so = new SWFObject('/plugins/flv_player/player.swf','mpl','232','20','9');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','false');
	so.addParam('stretching','none');
	so.addParam('wmode','transparent');
    so.addParam('flashvars','file='+ theFile +'&autostart=true');
    
	if (go) { so.addVariable("autostart","true"); }
	so.write('player' + id);
	//console.log(theFile);
}

function createaudioplayerbig(theFile, go, id) {
	var so = new SWFObject('/plugins/flv_player/player.swf','mpl','580','20','9');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','false');
	so.addParam('stretching','none');
	so.addParam('wmode','transparent');
    so.addParam('flashvars','file='+ theFile +'&autostart=true');
    
	if (go) { so.addVariable("autostart","true"); }
	so.write('player' + id);
	//console.log(theFile);
}


/*
	Jquery popup window
*/

$.fn.popupWindow = function(instanceSettings){
		
	return this.each(function(){
	
	$(this).click(function(){
	
	$.fn.popupWindow.defaultSettings = {
		centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
		centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
		height:500, // sets the height in pixels of the window.
		left:0, // left position when the window appears.
		location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
		menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
		resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
		scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
		status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
		width:500, // sets the width in pixels of the window.
		windowName:null, // name of window set from the name attribute of the element that invokes the click
		windowURL:null, // url used for the popup
		top:0, // top position when the window appears.
		toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
	};
	
	settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});
	
	var windowFeatures =    'height=' + settings.height +
							',width=' + settings.width +
							',toolbar=' + settings.toolbar +
							',scrollbars=' + settings.scrollbars +
							',status=' + settings.status + 
							',resizable=' + settings.resizable +
							',location=' + settings.location +
							',menuBar=' + settings.menubar;

			settings.windowName = this.name || settings.windowName;
			settings.windowURL = this.href || settings.windowURL;
			var centeredY,centeredX;
		
			if(settings.centerBrowser){
					
				if ($.browser.msie) {//hacked together for IE browsers
					centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
					centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
				}else{
					centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
					centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
				}
				window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
			}else if(settings.centerScreen){
				centeredY = (screen.height - settings.height)/2;
				centeredX = (screen.width - settings.width)/2;
				window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
			}else{
				window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top).focus();	
			}
			return false;
		});
	});	
};

/*
	SMS character counter
*/
function counter(){
    var message = $('#message').val();
    var limit = 160;
    
    if(message.length > limit){
        message = message.substring(0, limit);
        $('#message').val(message);
    }
    
    $('#charcount').html(limit - message.length);
}

$(function() {

    var addClickHandlers = function() {
		/*
			playlist hovers
		*/
		$('div.playlist-container a').hover(function(){
			$(this).children('span').show();
		},function(){
			$(this).children('span').hide();
		});
		/*
			playlist currently playing
		*/
		$('div.playlist-container a').click(function(){
			$('#currently_playing').html($(this).attr('title'));
		});
		/*
			playlist open in popup
		*/
		$('.popup_player').popupWindow({ 
			centerBrowser: 1,
			width: 250,
			height: 278
		}); 
		$('.popup_player_playlist').popupWindow({ 
			centerBrowser: 1,
			width: 250,
			height: 278
		}); 
		
		//fixed banner-------------------------------------------------------------------------
		var msie6 = $.browser == 'msie' && $.browser.version < 7;
  
		if (!msie6) {
			var top = $('#ad_160x600').offset().top - parseFloat($('#ad_160x600').css('margin-top').replace(/auto/, 0));
			$(window).scroll(function (event) {
				// what the y position of the scroll is
				var y = $(this).scrollTop();
				
				// whether that's below the form
				if (y >= top) {
					// if so, ad the fixed class
					$('#ad_160x600 div').addClass('fixed');
				} else {
					// otherwise remove it
					$('#ad_160x600 div').removeClass('fixed');
				}
			});
		}  
		
		
		//freesms widget on first page --------------------------------------------------------
		$('#freesms_widget').click(function(){
			$("#widget-container").load("/sms-widget");
		});
		
        //close forms -------------------------------------------------------------------------
        $(".link_close").click(function() {
            $("div#forms").hide();
            $("div#forms").html("");
            $("div#forms").addClass("loader");
            $("div#forms_upload").hide();
            $("div#forms").html("");
            $("div#forms").addClass("loader");
        });
        $(".link_hide").click(function() {
            $("div#forms").hide();
        });

        //handle IMAGE rotating ---------------------------------------------------------------
        $(".link_rotate_right, .link_rotate_left").click(function() {
            $("div#forms").html("");
            $("div#forms").addClass("loader");
            $("div#forms").load(this.href, function() {
                $("div#forms").removeClass("loader");
                $("div#forms").css("background-color","#bde1ea");
                $("div#forms").animate({ backgroundColor: "#ffffff" }, 1000);
                addClickHandlers();
            });
            return false;
        });

        //handle ugc UPLOAD -------------------------------------------------------------------
        $(".link_add_picture_video").click(function() {
            $("div#forms").hide();
            $("div#forms_upload").css("background-color","#bde1ea");
            $("div#forms_upload").show();
            $("div#forms_upload").animate({ backgroundColor: "#ffffff" }, 1000);
            return false;
        });

        //INBOX
        //reply -------------------------------------------------------------------------------
        $("#inbox_expanded a.link_reply").click(function() {
            $(".reply").slideDown('fast');
            return false;
        });

        //close -------------------------------------------------------------------------------
        $("#inbox_expanded a.link_close").click(function() {
            //show all hidden items
            $("#inbox > .item").show();
            //..and close this one
            $("#inbox_expanded").remove();
            $(".reply").show();
            return false;
        });

        //accept friend request -------------------------------------------------------------------------------
        $("#inbox_expanded").children("div.friend_request").children(".content").children(".link_accept", this).click(function() {
            $("#inbox_expanded").load(this.href, addClickHandlers);
            return false;
        });

        //voting - hot or not---------------------------------------------------------------------------------
        $(".thumb_up, .thumb_down").click(function(){
            $("#hot_or_not").load(this.href, addClickHandlers);
            return false;
        });

        $('textarea').autogrow({lineHeight:14,paddingLeft:7,paddingRight:7,paddingTop:3,paddingBottom:3});

        //show password field if selected -----------------------------------------------------
        $("#privacy").bind("change",function(){
            if ($("#privacy").val() == "password") {
                $("#privacy_password").slideDown("fast");
            } else {
                $("#privacy_password").slideUp("fast");
            }
        });

        //new message toggle input fields
        $("div#i_choose input").change(function() {
            if ($(this).val() == "nickname") {
                $("#i_msisdn").hide();
                $("#i_nickname").show();
            } else {
                $("#i_nickname").hide();
                $("#i_msisdn").show();
            }
        });

        //submit a form to delete message in inbox
        $("#form_m > div.content > a.link_delete").click(function() {
            $("form#form_m").trigger('submit');
        });

        //embed for home / gallery
        $("input#image_embed").val("[img]" + $("#selected_image").attr("src") + "[/img]");
        $("input#image_embed, input#image_link").focus(function() {
            this.select();
        });
    }
    addClickHandlers();

        //open new message form----------------------------------------------------------------
        $("a.link_new_message").click(function() {
            $("div#forms").show();
            $("div#forms").load("/getnewmessage", function() {
                $("div#forms").removeClass("loader");
                $("div#forms").css("background-color","#bde1ea");
                $("div#forms").animate({ backgroundColor: "#ffffff" }, 1000);
                addClickHandlers();
            });
            return false;
        });

    //load ajax ugc -----------------------------------------------------------------------
    $("a.ugc_thumb", this).click(function() {
        //$("div#forms").html("");
        //$("div#forms").addClass("loader");
        $("div#forms_upload").hide();
        $("div#forms").show();
        $("div#forms").load(this.href, function() {
            $("div#forms").removeClass("loader");
            $("div#forms").css("background-color","#bde1ea");
            $("#forms").animate({ backgroundColor: "#ffffff" }, 1000);
            //$('a[rel*=facebox]').facebox();
            addClickHandlers();
        });
        return false;
    });

    //load album form fields --------------------------------------------------------------

    $("#albums a.edit, .link_add_album", this).click(function() {
        $("div#forms").show();
        $("div#forms").load(this.href, function() {
            $("div#forms").removeClass("loader");
            $("div#forms").css("background-color","#bde1ea");
            $("div#forms").animate({ backgroundColor: "#ffffff" }, 1000);
            addClickHandlers();
        });
        return false;
    });

	//load music form fields
	
    $("#playlist a.edit-song", this).click(function() {
        $("div#forms").show();
        $("div#forms").load(this.href, function() {
            $("div#forms").removeClass("loader");
            $("div#forms").css("background-color","#bde1ea");
            $("div#forms").animate({ backgroundColor: "#ffffff" }, 1000);
            addClickHandlers();
        });
        return false;
    });


    //INBOX -------------------------------------------------------------------------------
    //select all checkboxes
    $('#all').click(function(){
        if ($('#all').attr('checked')) {
            $('.msg_cb').attr('checked','checked');
        } else {
            $('.msg_cb').attr('checked','');
        }
    });

    //submit a form
    $("#inbox_delete, #inbox_markread").click(function() {
        //set new form action and submit it
        $("form#inbox_form").attr("action", this.href);
        $("form#inbox_form").trigger('submit');
    });

    //shift select plugin
    $.fn.enableCheckboxRangeSelection = function() {
        var lastCheckbox = null;
        var $spec = this;
        $spec.bind("click", function(e) {
            if (lastCheckbox != null && e.shiftKey) {
                $spec.slice(
                Math.min($spec.index(lastCheckbox), $spec.index(e.target)),
                Math.max($spec.index(lastCheckbox), $spec.index(e.target)) + 1
                ).attr({checked: e.target.checked ? "checked" : ""});
            }
            lastCheckbox = e.target;
        });
        return $spec;
    };
    $("input.msg_cb").enableCheckboxRangeSelection();

    var test = false;
    //click on div
    $("div#inbox > div.item", this).click(function() {
        if(!test) {
            ref = $(this);
            //get type and id from element's id
            pos     = this.id.indexOf('-');
            type    = this.id.substring(0,pos);
            id      = this.id.substring(pos + 1);
            //console.log($(this));
            //setloader icon to this item
			//console.log(ref);
			ref.find('span.itemico').hide();
            ref.addClass('loader');
            //remove all previously expanded items
            $("#inbox_expanded").remove();
            //show all hidden items
            $("#inbox > .item").show();
            //remove loader class to all other items

            ref.removeClass("new");
            if ($(this).attr('class').split(' ').slice(-2) == 'first,loader') {
                $(ref).after('<div id="inbox_expanded" class="first"></div>');
            } else {
                $(ref).after('<div id="inbox_expanded"></div>');
            }
            $("#inbox_expanded").load("/inboxitem/type/" + type + "/id/" + id, function() {
                $(ref).hide();
                ref.removeClass('loader');
				ref.find('span.itemico').show();
                addClickHandlers();
            });
        } else {
            test = false;
        }
    });

    //click on checkbox
    $("input.msg_cb", this).click(function() {
        test = true;
    });

    //close error and success messages ---------------------------------------------------
    $('#error_close').click(function(){
        $('#error').hide();
    });
    $('#success_close').click(function(){
        $('#success').hide();
    });

    //toggle user info --------------------------------------------------------------------

    $('#show_user_info').click(function(){
        $('#s_user_info ul li').removeClass('hidden');
        $('#show_user_info').hide();
        $('#hide_user_info').show();
        return false;
    });

    $('#hide_user_info').click(function(){
        $("#s_user_info .additional").addClass('hidden');
        $('#hide_user_info').hide();
        $('#show_user_info').show();
        return false;
    });

    //send lost password ------------------------------------------------------------
    $('.link_lost_pass').click(function(){
        $('#login').hide();
        $('#lost_pass').show();
        return false;
    });
	
	$('.lost-pass-cancel').click(function(){
        $('#lost_pass').hide();
        $('#login').show();
        return false;
	});

	//commenting on wall--------------------------------------------------------------
	$('a.add-comment').click(function(){
		if ($(this).siblings('ul.comments').children('.wall_comment').css('display') == 'none') {
			if ($(this).siblings('ul.comments').attr('rel') == 'empty') {
				$(this).siblings('ul.comments').show();
			}
			$(this).siblings('ul.comments').children('.wall_comment').show();
		} else {
			if ($(this).siblings('ul.comments').attr('rel') == 'empty') {
				$(this).siblings('ul.comments').hide();
			}
			$(this).siblings('ul.comments').children('.wall_comment').hide();
		}
		return false;
	});
    //show all comments (delegate)
	$('div#wall div.day ul li ul.comments').click(function(e){
        var target = e.target;
        if ($(target).hasClass('show_all')) {
            currForm = $(this).children('li form.wall-comment-form');
            currCommentsHolder = $(this);
            currComments = currCommentsHolder.children('li.wcremove');
            $.get('/get-wall-comments/wall_id/' + $(target).attr('rel'), function(data) {
                currComments.remove();
                currForm.children('textarea#comment').val('');
                currCommentsHolder.prepend(data);
            });
        }
		return false;
	});
	//post new comment
    $('input#wall-comment-post').click(function() {
        //get parent form
        currForm = $(this).parent('form.wall-comment-form');
        currCommentsHolder = $(this).parents('ul.comments');
        currComments = currCommentsHolder.children('li.wcremove');
        //console.log(currComments);
        currForm.ajaxSubmit({
            type: 'POST',
            url: '/post-wall-comment/',
            success: function(data) {
                currComments.remove();
                currForm.children('textarea#comment').val('');
                currCommentsHolder.prepend(data);
            }
        });
    });

    //clear status and wall comment input -------------------------------------------------
    $("#wall_comment").focus(function(){
        if ($("#wall_comment").val() == $("#wall_comment").attr("title"))
            $("#wall_comment").attr("value", "");
    });

    $("#wall_comment").blur(function(){
        if ($("#wall_comment").val() == "")
            $("#wall_comment").attr("value", $("#wall_comment").attr("title"));
    });

    $("#comment_submit").click(function(){
        if ($("#wall_comment").val() == "" || $("#wall_comment").val() == $("#wall_comment").attr("title")) {
            return false;
        }
    });

    $("#user_status").focus(function(){
        if ($("#user_status").val() == $("#user_status").attr("title"))
            $("#user_status").attr("value", "");
    });

    $("#user_status").blur(function(){
        if ($("#user_status").val() == "")
            $("#user_status").attr("value", $("#user_status").attr("title"));
    });

    $("#status_submit").click(function(){
        if ($("#user_status").val() == "" || $("#user_status").val() == $("#user_status").attr("title")) {
            return false;
        }
    });

    //redirect after category change in public gallery-------------------------
    $("select#choose_category").change(function() {
        //console.log($(this).val());
        //alert("redirect");
        top.location = $(this).val();
    });

    //msisdn for login
    $("#phone_number").focus(function(){
        if ($("#phone_number").val() == $("#phone_number").attr("title"))
            $("#phone_number").attr("value", "");
    });
    $("#phone_number").blur(function(){
        if ($("#phone_number").val() == "")
            $("#phone_number").attr("value", $("#phone_number").attr("title"));
    });

    //validation of empty inputs----------------------------------------------------------------------------
    $("#add_comment_form").submit(function(){
        if ($("#comment").val() == "") {
            $("#add_comment_form > span").append(" (field must not be empty)").css({"color":"#ff0000"});
            return false;
        }
    });

    $("#edit_album_form").submit(function(){
        if ($("#album_title").val() == "") {
            $(".lbl_album_title").append(" (field must not be empty)").css({"color":"#ff0000"});
            return false;
        }
    });

    //send message in sidebar----------------------------------------------------------------------------
    $("#s_main_image .link_send_msg").click(function(){
        $("#s_send_msg").slideDown('fast');
        $("#s_main_image .link_send_msg").css({'font-weight':'bold'});
        return false;
    });

    $("#s_send_msg .link_close_msg").click(function(){
        $("#s_send_msg").slideUp('fast');
        $("#s_main_image .link_send_msg").css({'font-weight':'normal'});
        return false;
    });

    //invite friend in sidebar----------------------------------------------------------------------------
    $("#s_main_image .link_invite_friend").click(function(){
        $("#s_invite_friend").slideDown('fast');
        $("#s_main_image .link_invite_friend").css({'font-weight':'bold'});
        return false;
    });

    $("#s_invite_friend .link_close_msg").click(function(){
        $("#s_invite_friend").slideUp('fast');
        $("#s_main_image .link_invite_friend").css({'font-weight':'normal'});
        return false;
    });

    //add_news
    $("#add_news").click(function() {
        $("div#forms").show();
    });


    //profile gallery - AJAX stuff---------------------------------
    //TODO reduce this to only one request and return JSON object
    //on load set embed code

    function addGalleryHandlers() {
        var tmp_link = $("a#link_audio_download").attr('href');
        if (tmp_link) {
            $("a#link_audio_download").attr('href', tmp_link.replace('&',''));
        }
        $("input#image_embed, input#image_link").focus(function() {
            this.select();
        });
        $("input#image_embed").val("[img]" + $("#selected_item img.image").attr("src") + "[/img]");
    }
    addGalleryHandlers();
    
    $("a.pgthumb").click(function() {
		var height = $("#active-item").attr("height");
		$("#image-preloader").css("top",(height/2)-9);
		$("#image-preloader").css("left",180);
        $("#image-preloader").show();
		if (response) {
            response = false;
            url = this.href;
            $.get(url, function(data) {
                $("div#selected_item").html(data);
                $("input#image_embed").val("[img]" + $("#selected_item img.image").attr("src") + "[/img]");
                response = true;
                addGalleryHandlers();
            });
            $.get("/getugccomments/ugcid/" + $(this).attr("rel"), function(data) {
                $("#comments_container").html(data);
            });
        }
        return false;
    });
    
    //gallery (open image) delegate
    $("div#selected_item").click(function(e) {
        var target = e.target;
        id = $(target).attr('id');
        if (id == 'link_audio_download') {
            return true;
        }
        url = $(target).attr("href");
        ugcid = $(target).attr("rel");
        reload = $(target).hasClass('reload');
        next = $(target).hasClass('next');
        previous = $(target).hasClass('previous');
        //get id of first and last photo
        first   = $("div#gallery > div.item > a.first").attr('rel');
        last    = $("div#gallery > div.item > a.last").attr('rel');
        //we're on first or last photo - refresh
        if (((last == ugcid) && next) || ((first == ugcid) && previous)) {
            //console.log('first or last');
            //get current url
            var url = document.location.toString();
            if (!url.match('page')) {
                url = url + '/page/1';
            }
            parts = url.split('/');
            url = '';
            var pageIndex;
            var page = 2;
            for (var i in parts) {
                if (parts[i] == "page") {
                    i++;
                    pageIndex = i;//remember index of page
                    page =  parseInt(parts[i]);
                } else if (parts[i] == "ugcid") {
                    //remove ugcid from url
                    parts.splice(parseInt(i),2);
                }
            }
            if (next) page++;
            if (previous && (page > 1)) page--;
            parts[pageIndex] = page;

            url = parts.join('/');

            //console.log(url);
            window.location = url;
            return false;
        }
        if (url && url != "#" && !reload) {
            //console.log("Url:" + url);
            parts = url.split('/');
            found=false;
            jQuery.each(parts, function(i, val) {
                if (val == 'ugcid') {
                    found=i;
                }
            });
            if (found) {
                ugcid = parts[(found+1)];
            if (response && ((parts[1] == 'getprofileugc') || (parts[1] == 'getugc'))) {
                response = false;
                $.get(url, function(data) {
                    $("div#selected_item").html(data);
                    response = true;
                });
                //also load comments for this image
                $.get("/getugccomments/ugcid/" + ugcid, function(data) {
                    $("#comments_container").html(data);
                });
            }
            }

            return false;
        }        
        return true;
    });

    //ispace TV
    $(".tv-button").click(function() {
		$("#channels").hide();
		$("#channels-container").show();
        $("#channels-container").load("/channel-single/categoryId/" + $(this).attr('rel'));
		$("#featured-ispace-tv").hide();
		$("#featured-ispace-galleries").hide();
		$("#featured-user-galleries").hide();
		$("#featured-back").show();
		$(".featured-btns-item").hide();
		$("#channels-tabs li a").removeClass("active");
		$("#cooliris-container").hide(); //this was missing, don't know why
		$(this).addClass("active");
        return false;
    });

	//featured buttons
	$("#featured-ispace-tv").click(function(){
		$("#cooliris").hide();
		$("#channels").show();
        return false;
	});
	$("#featured-ispace-galleries").click(function(){
		$("#channels").hide();
		$("#cooliris-container").show();
		$("#cooliris-container").load('/cooliris/categoryId/349');
        return false;
	});	
	$("#featured-user-galleries").click(function(){
		$("#channels").hide();
		$("#cooliris-container").show();
		$("#cooliris-container").load("/cooliris");
        return false;
	});
	$("#featured-back").click(function(){
		$(".featured-btns-item").show();
		$("#channels").show();
		$("#channels-container").html("").hide();
		$("#featured-back").hide();
		$("#featured-ispace-tv").show();
		$("#featured-ispace-galleries").show();
		$("#featured-user-galleries").show();
		$("#channels-tabs li a").removeClass("active");
        return false;
	});

    /* facebook connect */
    $("form#form-connect-login").ajaxForm({
        dataType: 'json',
        success: function(data){
            if (data.success != false){
                //redirect to first page
                top.location = '/';
            } else {
                $('#msg-form-1').html(data.msg).show();
				$.fn.colorbox.resize();
				$.fn.colorbox.resize();
            }
        }
    });

    /* facebook connect */
    $("form#form-connect-register").ajaxForm({
        dataType: 'json',
        success: function(data){
            if (data.success != false){
                $("input#msisdn2").val(data.msisdn);
				$.fn.colorbox({inline:true,href:'#fb-register-pin'});
            } else {
                $('#msg-form-2').html(data.msg).show();
				$.fn.colorbox.resize();
				$.fn.colorbox.resize();
            }
        }
    });
	
    /* facebook connect */
    $("form#fb-register-pin-form").ajaxForm({
        dataType: 'json',
        success: function(data){
            if (data.success != false){
                $.fn.colorbox({inline:true,href:'#fb-final-msg'});
            } else {
                $('#msg-form-3').html(data.msg).show();
				$.fn.colorbox.resize();
				$.fn.colorbox.resize();
            }
        }
    });
})