admmedia={};
admmedia.site2010={
	projectListHidden: false,
	current_project_id: 0,
	init: function() {
		this.addTooltipCssClass();
		 
		this.addProjectTooltips();
		//projects
		this.addProjectsCont();
		this.addProjectControls();
		//js-goback
		this.jsGoback();
		//fancybox
		this.addFancy();
		//files
		this.addFilesControl();
		//jqtransitions
		this.addJqTransitions();
		//tiptip
		this.addTipTip();
	},
	addTipTip: function() {
		var tiptip_base={fadeIn:200,fadeOut:200};
		jQuery(".tooltip").tipTip(tiptip_base);
	},
	addJqTransitions: function() {
		$(".slides").slides({
			preload: false,
			pagination : false,
			generatePagination: false,
			play :  5000,
			generateNextPrev :true,
			next: "btn-purple-right",
			prev: "btn-purple-left",
			container :'slides-cont'
		});
	},
	addFilesControl: function() {
		jQuery(".show-version-link").click( function() {
			jQuery(this).parent().parent().parent().find("div.versions").toggle();
			jQuery(this).toggleClass("on").blur();
			return false;
		});
	},
	addProjectsCont: function() {
		//ukryj liste projektow
		this.projectListHidden=true;
		$(".lista-projektow-cont").hide();
		//link
		//przenies link do path
		$(".projects-list-select").hide();
		$('.path').append( $(".projects-list-select") );
		$(".projects-list-select").show();

		$('.page-content').before( $(".lista-projektow-cont") );

		$(".lista-projektow-controls").hide();
		$('.page-content').before( $(".lista-projektow-controls") );
		$(".lista-projektow-controls").show();

		$(".lista-projektow-show-link").click( function() {
			if(admmedia.site2010.projectListHidden) {
				$(this).toggleClass("lista-projektow-show-link-open");
				admmedia.site2010.projectListHidden=false;
				$(".lista-projektow-cont").show();
			} else {
				$(this).toggleClass("lista-projektow-show-link-open");
				admmedia.site2010.projectListHidden=true;
				$(".lista-projektow-cont").slideUp("fast");
			}
			return false;
		});
		//link projektu
		$(".lista-projektow-link").click(admmedia.site2010.getProject);
	},
	addProjectControls: function() {
		$(".lista-projektow-prev-link").click( function() {
			admmedia.site2010.loadProjectById("prev");
		});
		$(".lista-projektow-next-link").click( function() {
			admmedia.site2010.loadProjectById("next");
		});
	},
	getProject: function(d) {
		var el=$(d.target);
		var project_id=el.attr("rel").split("-")[1];
		admmedia.site2010.loadProjectById(project_id);
	},
	loadProjectById: function(project_id) {
		//pokaz loading
		$(".lista-projektow-projekt-cont").slideUp("fast", function() {
			$(".lista-projektow-loading").show();
			//wczytaj projekt
			$.ajax({
				url: "/projects/blocks/project/project_id:"+project_id+"/current_project_id:"+admmedia.site2010.current_project_id+"/",
				success: function(data) {
					$(".lista-projektow-loading").hide();
					$(".lista-projektow-projekt-cont").html(data);
					$(".lista-projektow-projekt-cont").slideDown("fast");
				}
			});
		});
		//oznacz link jako przeczytany
		this.markProjectAsRead(project_id);
	},
	markProjectAsRead: function(project_id) {
		$(".projekt-link-"+project_id).addClass("was-read");
	},
	addTooltipCssClass: function() {
		$(".top-menu a").addClass("tooltip");
	},
	jsGoback: function() {
		$(".js-goback").click( function() {
			history.back();
			return false;
		});
	},
	addFancy: function() {
		$("a.fancy-img").fancybox({
			'type' : 'image',
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	200,
			'speedOut'		:	200,
			'overlayShow'	:	true,
			overlayOpacity: 0.7,
			titleShow: false,
			overlayColor: '#ffffff'
		});
	},
	addTooltips: function() {

		$(".tooltip").qtip({
			//content:  $(this).attr('title'),
			content: {
				text: false
			},
			position: {
				corner: {
					tooltip: "topMiddle",
					target: "bottomMiddle"
				}
			},
			show: {
				effect:{
					type: 'slide'
				}
			},

			style: {

				padding: 5,
				background: '#A5214F',
				color: '#fff',
				textAlign: 'center',
				border: {
					width: 7,
					radius: 7,
					color: '#A5214F'
				},
				tip: 'topMiddle',
				name: 'dark' // Inherit the rest of the attributes from the preset dark style
			}
		});
	},
	addProjectTooltips: function() {

		$('.project-tooltip').each( function() {
			var html=$(this).next().html();

			var noImgProp={
				content: {
					text: $(this).attr('title')
				},
				position: {
					corner: {
						target: 'bottomMiddle',
						tooltip: 'topMiddle'
					},
					adjust: {
						screen: true
					}
				},
				show: {
					effect: {
						type: 'slide'
					}
				},
				style: {
					padding: 5,
					background: '#1D1D1D',
					border: {
						width: 7,
						radius: 7,
						color: '#1D1D1D'
					},
					tip: 'topMiddle',
					name: 'dark'

				}
			};
			var noTitleProp={
				content: {
					text: html
				},
				position: {
					corner: {
						target: 'bottomMiddle',
						tooltip: 'topMiddle'
					},
					adjust: {
						screen: true
					}
				},
				show: {
					effect:{
						type: 'slide'
					}
				},
				style: {
					padding: 0,
					background: '#1D1D1D',

					border: {
						width: 7,
						radius: 7,
						color: '#1D1D1D'
					},
					tip: 'topMiddle',
					name: 'dark',
					width: 125
				}
			};
			if(html!="") {
				$(this).qtip(noTitleProp);
			} else {
				$(this).qtip(noImgProp);
			}
		});
	}
};

admmedia.ui={};
admmedia.ui.gallery={
	addGalleryBigSmallBehaviour: function(cont_id) {
		//add fancy
		this.addFancy(cont_id);
		this.addTooltips(cont_id);
		//add link behaviour
		this.addLinkControls(cont_id);
	},
	addFancy: function(cont_id) {
		admmedia.site2010.addFancy();
	},
	addTooltips: function(cont_id) {
		//no tooltip
	},
	addLinkControls: function(cont_id) {
		$("#"+cont_id+" .gallery-big-small-sub-img-list .gallery-big-small-sub-img-content a").click( function(e) {
			var el=  $(this).parent().find("div.bigger-content");
			$("#"+cont_id+" .gallery-big-small-main-img-content").html(el.html());
			//dodaj fancy
			admmedia.ui.gallery.addFancy("#"+cont_id+" .gallery-big-small-main-img-content");
			return false;
		});
	}
};


