/* file: User.js */
var User = Class.create(Application.prototype, {
    
    /*basicInit: function () {
        
        this.ajaxForm('checkNickForm', {
            'onSuccess': this.checkNickFormProcessResponse.bind(this),
            'errorList': {
                403: this.checkNickFormProcessResponse.bind(this, 'checkNickForm'),
                409: this.checkNickFormProcessResponse.bind(this, 'checkNickForm')
            }
        });
        //Application.registerHistoryCallback('user', this.handleHashChange.bind(this));
    },*/
    checkNickAvailability: function (checkNickAvailabilityUrl) {
        //var nick = document.getElementById('nick').value;
        var nick = $('#nick').val();
        this.ajaxPost(checkNickAvailabilityUrl, {nick: nick}, {
            'onSuccess': function (response) {
            
                this.checkNickFormProcessResponse(response);
            }.bind(this)
        });
        return false;
    },
    
    identificationCookie: function( cookieValue ) {
        
        // Create cookie value
        var cookieInput = '<input type="hidden" name="gemius_status_id" value="' + cookieValue + '" />';    
        // Append input to comment forms
        $('#checkNickForm').prepend( cookieInput );
        // Remove swf object
        $('#usercookie').remove();
    },

    addEntryActive: false,
    addRecommendationActive: false,    

    entryBox:   '<div id="entryBox">' +
                    '<form id="entryForm" action="%reportUrl" method="post">'+
                        '<label for="content">' + 
                              '%label'  +
                            ' <textarea cols="60" rows="10" name="entryContent"> </textarea>'+
                        '</label>' +
                        '<input type="submit">'+
                    '</form>'+
                '</div>',
	checkNickFormProcessResponse: function (obj) {
        if (obj.isNickAvailable) {
            $('#idDivNickavailable').attr('class', 'actionOK');
            $('#nick').attr('class', 'dataOK');
        } else {
            $('#idDivNickavailable').attr('class', 'actionError');
            $('#nick').attr('class', 'error');
        }
        $('#idDivNickavailable').attr('innerHTML', obj.text);
        return false;
    },
    
	deleteOrder: function (deleteOrderUrl) {

		this.ajaxPost(deleteOrderUrl, {}, {
			onSuccess: function (obj) {
				if (obj.content) 
					$('#uploadOrders').html(obj.content);
			}.bind(this)
		});
		return false;
	},
    
    recommend : function(recommendUrl) {
    
        if (this.addRecommendationActive) {
            return false;
        }
        this.addRecommendationActive = true;    
        
        user.ajaxPost(recommendUrl, {}, {
            onSuccess: function (obj) {
               $('#recommend').remove();
               
               this.showMsg(Application_lang.recommendationAdded, this.REQUEST_STATUS_OK);                     
            }.bind(this)
        });
        return false;

    },
    
    report: function(reportUrl) {
    
        if (this.addEntryActive) {
            return false;
        }
        this.addEntryActive = true;
    
        var form = this.entryBox;
            form = form.replace('%reportUrl', reportUrl);
            form = form.replace('%label', Application_lang.addEntryLabel);
                                        
        $('body').append(form);
        
        $('#entryForm').submit(function() {
        
            var content = $('textarea[name=entryContent]').val();
            
            user.ajaxPost(reportUrl, {content: content}, {
            	onSuccess: function (obj) {
                   $('#entryBox').remove();
                   $('#report').removeAttr('href');
                   $('#report').removeAttr('onclick');
                   
                   this.showMsg(Application_lang.entryAdded, this.REQUEST_STATUS_OK);                     
            	}.bind(this)
        	});
            return false;
        });
    
    },
    
    showFirstLoggin: function(first) {
        var self = this;
    
        if (first) {
            this.showWelcomeMsg(Application_lang.firstLogginMessage, this.REQUEST_STATUS_INFO, self.hideFirstLoggin);
            this.showFirstLogginCommentBox(true);
        }
        
        /*if (!$('#user-albums').html()) {
            this.showFirstLogginAlbumBox(true);
        }*/

        if (!$('#user-photos #smallPhotos .small').html()) {
            this.showFirstLogginPhotoBox(true);
        }        
        
        /*if (!$('.recentPhotoComments').html()) {
            this.showFirstLogginUserCommentBox(true);
        }*/              
            
    },
    
    hideFirstLoggin: function() {
         //user.showFirstLogginAlbumBox(false);    
         user.showFirstLogginPhotoBox(false);
         //user.showFirstLogginUserCommentBox(false);
         user.showFirstLogginCommentBox(false);
    },
    
    showFirstLogginPhotoBox: function(visible) {
    
        if (visible) {
            var html = this.createEmptyBox("emptyPhotos", "tu beda twoje foty", false);
            $('#user-photos').after(html);
        } else {
            $('#emptyPhotos').remove();
        }     
    },

    showFirstLogginUserCommentBox: function(visible) {
    
        if (visible) {
            var html = this.createEmptyBox("emptyUserComments", "tu beda twoje komentarze", false);
            $('#recentCommentsHolder').after(html);
        } else {
            $('#emptyUserComments').remove();
        }     
    },       
    
    showFirstLogginAlbumBox: function(visible) {
    
        if (visible) {
            var html = this.createEmptyBox("emptyAlbum", "tu beda twoje albumy", 'Albumy');
            $('#commentsBox').before(html);
        } else {
            $('#emptyAlbum').remove();
        }            
    },
    
    showFirstLogginCommentBox: function(visible) {
    
        if (visible) {
            var html = this.createEmptyBox("emptyComments", 'Tutaj Twoi znajomi będą wyrażać zachwyt <img src="/images/emots/oklasky.gif" alt=""/> nad Twoją kolekcją zdjęć', false);
            $('#addCommentBox').before(html);
        } else {
            $('#emptyComments').remove();
        }    
    },
    
    createEmptyBox: function(id, msg, title) {
       
       var emptyBox = document.createElement('div');
            $(emptyBox).addClass('emptyBox');
            $(emptyBox).attr('id', id);
            
            var arrow   = document.createElement('span');
                $(arrow).addClass('arrow');      
            var text   = document.createElement('span');
                $(text).addClass('text');
                $(text).html(msg);
            
            if( title !== false ) {
                var heading = document.createElement('span');
                  $(heading).addClass('heading');
                  $(heading).html( title );
                  
                $(emptyBox).append(heading);
            }
            $(emptyBox).append(text);
            $(emptyBox).append(arrow);            
           
        return emptyBox;             
    }
    
});

$(document).ready( function () { user = new User(); } ); //user.basicInit();

/* file: Favourites.js */
var Favourites = Class.create(Application.prototype, {
    
    init: function() {
		
    },
    
    add: function(url, link, message) {
        this.ajaxPost(url, {}, {
        	onSuccess: function (obj) {
	            if (obj.content) {
	                $('#addToFavourites')
                        .attr('href', link)
                        .html( '<span class="png buttons-common" id="button-w-ulubionych"></span>'+ message);
	            }
        	}.bind(this)
        });
        return false;
    },
    
    remove: function(favouriteId) {
        var sessionId = $.cookie(this.COOKIE_SESSION_NAME) == null ? '' : $.cookie(this.COOKIE_SESSION_NAME).substring(0, 32);
        $("input#favouriteId").val(favouriteId);
        $("input#sessionId").val(sessionId);
        $("#removeFavouritesForm").submit();
            
        return false;           
    }
        
});

$(document).ready( function () { favourites = new Favourites();} );

/* file: Comments.js */
var CommentsPaginationHistory = Class.create(Application.prototype, {
    lastId: 0,
    paginationHistory: new Array(),
    flagAdd: false   
});

var Comments = Class.create(Application.prototype, {
	
	START_PAGE: '',
	
	basicInit: function () {
		
		this.ajaxForm('addCommentForm', {
			'onSuccess': this.addCommentProcessResponse.bind(this, 'addCommentForm'),
			'errorList': {
				'403': this.addCommentProcessResponse.bind(this, 'addCommentForm'),
				'409': this.addCommentProcessResponse.bind(this, 'addCommentForm')
			}
		});
		Application.registerHistoryCallback('comments', this.handleHashChange.bind(this));
	},
	
	identificationCookie: function( cookieValue ) {
		
		// Create cookie value
		var cookieInput = '<input type="hidden" name="gemius_status_id" value="' + cookieValue + '" />';	
		// Append input to comment forms
		$('#addCommentForm').prepend( cookieInput );
		// Remove swf object
		$('#commentscookie').remove();
	},
	
	
	initPhotoComments: function (startPage) {
		
		if (null != startPage) {
			this.START_PAGE = startPage;
			if (!/^#comments\//.test(window.location.hash))
				this.getComments(startPage);
		}
        swfobject.embedSWF(
        		Application.urls.lsoFlash, // movie file
                'commentscookie', // movie id
                '1', // width
                '1', // height
                '9.0', // flash version
                false, // installer
                {
            		'funName': 'comments.identificationCookie'
        		}, // flashvars
                false, // params
                { name: 'commentscookie', id: 'commentscookie', swLiveConnect: 'true', allowScriptAccess: 'always' } // attributes
        );
        
        $('#newCommentBody').DefaultValue(Application_lang.enterYourComment);
	},

	getComments: function (url) {
    
		this.ajaxRequest(url, {
            'onSuccess': this.processGetCommentsResponse.bind(this)
		});
		return false;
	},
	
	processGetCommentsResponse: function (response) {

        if (response.recent) {
            $('#recentCommentsHolder').html(response.content);
            dateParser.makeWeb20Date();
            return;
        }

		$('#commentsHolder').html(response.content);
		$('#commentsPaginator').html(response.paginator);
		if ($('#commentsCount'))
			$('#commentsCount').html('(' + response.commentsCount + ')');
            
        $('#commentsPaginator a.nextLink').each( function(index, item) {
            $(item).click(function (href) {

                if(!commentsPaginationHistory.paginationHistory[href.match(/\d+$/)[0]] && (commentsPaginationHistory.paginationHistory[href.match(/\d+$/)[0]] != 0)){
                    commentsPaginationHistory.paginationHistory[href.match(/\d+$/)[0]]= commentsPaginationHistory.lastId; 
                    commentsPaginationHistory.lastId = href.match(/\d+$/)[0];                   
                }     

                return false;
            }.bind(this, item.href))
        }.bind(this));    
            
            
		$('#commentsPaginator a.paginatorLink').each( function(index, item) {
			$(item).click(function (href) {

            
                $.historyLoad('comments/' + href.match(/\d+$/)[0]);
				
				return false;
			}.bind(this, item.href))
		}.bind(this));
        
        $('#commentsPaginator a.prevLink').each( function(index, item) {
            $(item).click(function (href) {
            
                var id = 0;

                if(commentsPaginationHistory.paginationHistory[href.match(/\d+$/)[0]]){
                    id = commentsPaginationHistory.paginationHistory[href.match(/\d+$/)[0]];    
                }

                $.historyLoad('comments/' + id);
                
                if(id == 0){
                    commentsPaginationHistory.paginationHistory = new Array();
                    commentsPaginationHistory.lastId = 0;   
                }
                
                return false;
            }.bind(this, item.href))
        }.bind(this));
        
        
        
		
		// show delete buttons if needed
		$('#commentsHolder .comment-remove').each( function(index, item) {
			var item = $(item);
			var canDelete = core.isUser(item.attr('commentOwnerUin')) || core.isUser(item.attr('photoOwnerUin'));
			if (canDelete)
					item.show();
		}.bind(this));
		nickManager.unfreezeCollecting('comments');
		nickManager.collectUins();
		dateParser.makeWeb20Date();
        smallImagesGradientNick( $('#sidebar #commentsHolder').find('.comment-meta'), 300 );
        commentContentGradient( $('#sidebar #commentsHolder').find('.comment-content'), 300 );
	},
    
	handleHashChange: function (params) {
		return this.getComments(this.START_PAGE.replace(/\d+$/, params[0]));
	},
	
	deleteComment: function (deleteCommentUrl, postFields) {

		this.ajaxPost(deleteCommentUrl, postFields, {
			'onSuccess': function (response) {
				this.processGetCommentsResponse(response);
			}.bind(this)
		});
		return false;
	},
	
	addCommentProcessResponse: function (id, obj) {
		
		var errorMsgId = id + 'ErrorMsg';
		if (obj.error) {
            this.showNotification(obj.error, this.REQUEST_STATUS_ERROR, $('#commentsBox') );
			//$('#' + errorMsgId).html(obj.error);
		} else if (obj.message){
			$('#addCommentBox').html('<p class="logInLabel">' + obj.message + '</p>');
            if( $('#commentsBox').find('.messageBox').length > 0 ) { $('#commentsBox').find('.messageBox').remove(); }
            this.processGetCommentsResponse(obj);
		}
		return false;
	}
		
});

var comments = new Comments();
var commentsPaginationHistory = new CommentsPaginationHistory();

$(document).ready( function () { comments.basicInit(); });

/* file: Emoticons.js */
var Emoticons = Class.create(Application.prototype, {
    // Emoticons
    start: function(editBoxId, inputId) {
        // Append the emoticon button to the form
        $('#'+editBoxId).prepend( this.createEmoticonsButton() );
        // Append the emoticon window to the form
        $('#'+editBoxId).append( this.createEmoticonsWindow() );
        // Bind actions
        $('#emoticons-toggle').bind('click', function(e) {
            $('#emoticons-window').toggle();  
            emoticons.alterEmoticonsButton();          
            e.preventDefault();
        });
        $('#emoticons-window').find('td').each( function() {
            $(this).bind('click', function() {
                $('#'+inputId).HideDefaultValue().val( $('#'+inputId).val() + '<' + $(this).attr('class') + '> ' );
                $('#emoticons-window').toggle();
                emoticons.alterEmoticonsButton();
            });
        });
    },
    alterEmoticonsButton: function () {
        if ($('#emoticons-window').css('display') != 'none') {    
            $('#emoticons-button').css('background', 'transparent url("/images/ggalerie-sprite.png") no-repeat -89px -218px');
        }
        else {
            $('#emoticons-button').css('background', 'transparent url("/images/ggalerie-sprite.png") no-repeat -89px -199px');
        }
    },
    createEmoticonsButton: function() {
        return '<a href="#" id="emoticons-toggle" class="grey block button"><span id="emoticons-toggle-span"><span class="png" id="emoticons-button"></span></span></a>';
    },
    createEmoticonsWindow: function() {
        var emoticonWindow = '<div id="emoticons-window" style="display:none; background-color: white; width: 96%; margin-bottom: 8px; float: left; margin-top: 5px; border: 1px solid #DECDB2;"><table><tr>';
        emoticonWindow += '<td align="center" class="aparat"><img src="/images/emots/aparat.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="beczy"><img src="/images/emots/beczy.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="bezradny"><img src="/images/emots/bezradny.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="blee"><img src="/images/emots/blee.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="boisie"><img src="/images/emots/boisie.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="buziak"><img src="/images/emots/buziak.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="buzki"><img src="/images/emots/buzki.gif" alt="" /></td></tr><tr>';
        emoticonWindow += '<td align="center" class="chytry"><img src="/images/emots/chytry.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="cwaniak"><img src="/images/emots/cwaniak.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" align="center" class="diabelek"><img src="/images/emots/diabelek.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="dobani"><img src="/images/emots/dobani.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="dokuczacz"><img src="/images/emots/dokuczacz.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="figielek"><img src="/images/emots/figielek.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="foch"><img src="/images/emots/foch.gif" alt="" /></td></tr><tr>';
        emoticonWindow += '<td align="center" class="glupek"><img src="/images/emots/glupek.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="haha"><img src="/images/emots/haha.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="hejka"><img src="/images/emots/hejka.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="hura"><img src="/images/emots/hura.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="jezyk_oko"><img src="/images/emots/jezyk_oko.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="jezyk"><img src="/images/emots/jezyk.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="klotnia"><img src="/images/emots/klotnia.gif" alt="" /></td></tr><tr>';
        emoticonWindow += '<td align="center" class="kotek"><img src="/images/emots/kotek.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="krzyk"><img src="/images/emots/krzyk.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="krzywy"><img src="/images/emots/krzywy.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="kwadr"><img src="/images/emots/kwadr.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="kwasny"><img src="/images/emots/kwasny.gif" alt="" /></td>';
        
        emoticonWindow += '<td align="center" class="kwiatek"><img src="/images/emots/kwiatek.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="luzik"><img src="/images/emots/luzik.gif" alt="" /></td></tr><tr>';
        emoticonWindow += '<td align="center" class="milczek"><img src="/images/emots/milczek.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="mniam"><img src="/images/emots/mniam.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="mruga"><img src="/images/emots/mruga.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="muza"><img src="/images/emots/muza.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="mysli"><img src="/images/emots/mysli.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="nerwus"><img src="/images/emots/nerwus.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="nie"><img src="/images/emots/nie.gif" alt="" /></td></tr><tr>';
        emoticonWindow += '<td align="center" class="oklasky"><img src="/images/emots/oklasky.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="okok"><img src="/images/emots/okok.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="ostr"><img src="/images/emots/ostr.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="paluszkiem"><img src="/images/emots/paluszkiem.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="papa"><img src="/images/emots/papa.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="papa2"><img src="/images/emots/papa2.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="pies"><img src="/images/emots/pies.gif" alt="" /></td></tr><tr>';
        emoticonWindow += '<td align="center" class="placze"><img src="/images/emots/placze.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="plask"><img src="/images/emots/plask.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="plotki"><img src="/images/emots/plotki.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="pocieszacz"><img src="/images/emots/pocieszacz.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="prosi"><img src="/images/emots/prosi.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="pytajnik"><img src="/images/emots/pytajnik.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="rotfl"><img src="/images/emots/rotfl.gif" alt="" /></td></tr><tr>';
        emoticonWindow += '<td align="center" class="smutny"><img src="/images/emots/smutny.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="spadaj"><img src="/images/emots/spadaj.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="stres"><img src="/images/emots/stres.gif" alt="" /></td>';
        
        emoticonWindow += '<td align="center" class="szok"><img src="/images/emots/szok.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="tak"><img src="/images/emots/tak.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="uoeee"><img src="/images/emots/uoeee.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="usmiech"><img src="/images/emots/usmiech.gif" alt="" /></td></tr><tr>';
        emoticonWindow += '<td align="center" class="wesoly"><img src="/images/emots/wesoly.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="w8"><img src="/images/emots/w8.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="wnerw"><img src="/images/emots/wnerw.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="wykrzyknik"><img src="/images/emots/wykrzyknik.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="wysmiewacz"><img src="/images/emots/wysmiewacz.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="ysz"><img src="/images/emots/ysz.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="zacieszacz"><img src="/images/emots/zacieszacz.gif" alt="" /></td></tr><tr>';
        emoticonWindow += '<td align="center" class="zakupy"><img src="/images/emots/zakupy.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="zalamka"><img src="/images/emots/zalamka.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="zawstydzony"><img src="/images/emots/zawstydzony.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="zeby"><img src="/images/emots/zeby.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="zlezkawoku"><img src="/images/emots/zlezkawoku.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="zly"><img src="/images/emots/zly.gif" alt="" /></td>';
        emoticonWindow += '<td align="center" class="zmeczony"><img src="/images/emots/zmeczony.gif" alt="" /></td>';
        emoticonWindow += '</tr></table></div>';
        
        return emoticonWindow;
    }
	
});

emoticons = new Emoticons();


/* file: Search.js */
var Search = Class.create(Application.prototype, {

    init: function() {
	/*
	    var albumsPerPage = 12;
	    var photosPerPage = 9;
		$('#albumResults .paginatorLink').unbind('click').click(function(e) {
			search.takePage($(this).text(), albumsPerPage, 'albumResults');
		});
		
		$('#smallPhotos .paginatorLink').unbind('click').click(function(e) {
			search.takePage($(this).text(), photosPerPage, 'smallPhotos');
		});
		
		var currentPhotoPage = parseInt($('#smallPhotos .png').text());

		$('#smallPhotos .paginatorNext').unbind('click').click(function(e) {
			search.takePage((currentPhotoPage+1), photosPerPage, 'smallPhotos');
		});
		
		$('#smallPhotos .paginatorPrev').unbind('click').click(function(e) {
			search.takePage((currentPhotoPage-1), photosPerPage, 'smallPhotos');
		});
		
		$('#smallPhotos .more').unbind('click').click(function(e) {
			$('#albumResults').html('');
			search.takePage(1, photosPerPage, 'smallPhotos');
		});
		
		var currentAlbumPage = parseInt($('#albumResults .png').text());
		
		$('#albumResults .paginatorNext').unbind('click').click(function(e) {
			search.takePage((currentAlbumPage+1), albumsPerPage, 'albumResults');
		});
		
		$('#albumResults .paginatorPrev').unbind('click').click(function(e) {
			search.takePage((currentAlbumPage-1), albumsPerPage, 'albumResults');
		});
		
		$('#albumResults .more').unbind('click').click(function(e) {
			$('#smallPhotos').html('');
			search.takePage(1, albumsPerPage, 'albumResults');
		});
		*/
		if( $('#curr_search_value').length > 0 ) {
			$('#search_value').val( $('#curr_search_value').val() );
		}
    },
   /* 
    takePage: function(page, limit, contentId) {
    	var searchValue = $('#curr_search_value').val();
    	if(contentId == 'smallPhotos') {
    		var action = 'ajaxphotosearch';
    	} else {
    		var action = 'ajaxalbumsearch';
    	}
    	var url= '/' + action + '/' + (page*limit-limit) + '/' + limit + '/' + searchValue;
    	$.ajax({
			'url': url,
			async: false, // must be synchronous
			dataType: 'json',
			success: function(resp) {
    		    $('#' + contentId).html(resp.content);
    		    this.init();
			}.bind(this),
            error: function(resp) {
				
            }.bind(this)
		});
        return false;
    }
    */
        
});

$(document).ready( function () { search = new Search();} );

/* file: Albums.js */
var Albums = Class.create(Application.prototype, {
	
	init: function () {
        this.registerEditable();
		this.renderAlbumViews();
        this.updateSessionId();
	},
	
	renderAlbumViews: function() {
        
        var counter = core.getModuleData('albumsViews', 'views');
        
        //for counts from 21 to 99
        var standardModCount = counter % 10;
        //for counts from 11 to 19 
        var excModCount = counter % 100;
        if (counter == 1) 
            var msg = Application_lang.albums_seen_one_time;
        else if (standardModCount > 1 && standardModCount < 5 && (excModCount < 12 || excModCount > 14)) {
            var msg = Application_lang.albums_seen_two_times;
        }
        else 
            var msg = Application_lang.albums_seen_many_times;
		
		var msg = msg.replace(/%value%/, counter);
		if ($('#albumViews')) {
		  $('#albumViews').html(msg);
		}
		
	},
	
	removeFromAlbum: function(url) {

        this.ajaxPost(url, {}, {
            onSuccess: function (data) {
                $('#photo_'+data.photoId).remove();
                $('.removePopup').remove();
                window.location.reload();
            }
        });
        return false;	   
	},
	
	remove: function(albumId) {
        
        $("input#albumId").val(albumId);
        $("#removeAlbumForm").submit();
	       	
        return false;	       	
	},
    
    edit: function (url) {
    
        var self = this;
    
        $('#button-edit').parent().hide();
        
        this.ajaxRequest (url, {
            'onSuccess' : function (resp) {
                self.showLightBox(resp.content);  
                self.updateSessionId();    
            }
        });
        return false;
    },
    
    save: function() {
        $("#updatePhotoForm").submit();
    }    
    
});
$(document).ready( function () {
    albums = new Albums();} 
);


/* file: Start.js */
var Start = Class.create(Application.prototype, {
	
    TIMEOUT : 3000,
    
    rotatingImages : [],
    loadedImages : {},
    lastIndex : -1,
    currentTimeout : null,
    
    
	init: function () {
		this.updateSessionId();
	}    
 
});
$(document).ready( function () { 
    start = new Start();
    
    
    if ($('#rotator').html()) {
        
        $('#rotator').galleryView({
            panel_width: 600,
            panel_height: 360,
            transition_speed: 1500,
            transition_interval: 5000,
            border: 'none',
            pause_on_hover: true
        });    

        $('img.nav-prev').remove();
        $('img.nav-next').remove();
        $('img.nav-overlay').remove();
    }    
    
} );





